Android 开发教程之 Service 详解
2010-02-22 16:14:00 来源:WEB开发网18. Log.e(TAG, "============> TestService.onBind");
19. return null;
20. }
21.
22. public class LocalBinder extends Binder {
23. TestService getService {
24. return TestService.this;
25. }
26. }
27.
28. @Override
29. public boolean onUnbind(Intent i) {
30. Log.e(TAG, "============> TestService.onUnbind");
31. return false;
32. }
33.
34. @Override
35. public void onRebind(Intent i) {
36. Log.e(TAG, "============> TestService.onRebind");
37. }
38.
39. @Override
40. public void onCreate {
41. Log.e(TAG, "============> TestService.onCreate");
42. _nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
43. showNotification;
44. }
45.
46. @Override
47. public void onStart(Intent intent, int startId) {
48. Log.e(TAG, "============> TestService.onStart");
49. }
50.
51. @Override
52. public void onDestroy {
53. _nm.cancel(R.string.service_started);
54. Log.e(TAG, "============> TestService.onDestroy");
55. }
56.
57. private void showNotification {
58. Notification notification = new Notification(R.drawable.face_1,
59. "Service started", System.currentTimeMillis);
60.
61. PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
62. new Intent(this, TestServiceHolder.class), 0);
63.
64. // must set this for content view, or will throw a exception
65. notification.setLatestEventInfo(this, "Test Service",
66. "Service started", contentIntent);
67.
68. _nm.notify(R.string.service_started, notification);
更多精彩
赞助商链接