Android服务开发全解析
1. 服务终止与通知
在服务销毁时,我们需要停止对 LocationListener 对象的更新,这会停止所有的后台处理。同时,我们要通知用户服务正在终止。以下是相关代码:
Notification(android.R.drawable.stat_notify_more,
"GPS Tracking", System.currentTimeMillis());
notify.flags |= Notification.FLAG_AUTO_CANCEL;
Intent toLaunch = new Intent(getApplicationContext(),
ServiceControl.class);
PendingIntent intentBack =
PendingIntent.getActivity(getApplicationContext(),
0, toLaunch, 0);
notify.setLatestEventInfo(getApplicationContext(),
"GPS Tracking", "Tracking stopped", intentBack);
notifier.notify(GPS_NOTIFY, notify);
super.onDestroy();
无论 start 方法被调用多少次, onDestroy() 方法只会被调用一次。
服务必须在 AndroidManifest.xml 权限文件
Android服务开发详解
超级会员免费看
订阅专栏 解锁全文
1118

被折叠的 条评论
为什么被折叠?



