use*_*858 8 service android android-ondestroy
我创建了一个应用程序,它在Service.onStartCommand()执行方法时显示Notification,并在Service.onDestroy()调用时隐藏通知.它适用于正常调用startService()和stopService().
服务代码:
@Override
public IBinder onBind(Intent intent)
{
return null;
}
@Override
public void onCreate()
{
super.onCreate();
nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
//Some code here
showNotification();
return START_NOT_STICKY;
}
@Override
public void onDestroy()
{
super.onDestroy();
nm.cancel(R.string.service_started);
}
Run Code Online (Sandbox Code Playgroud)
问题:当我的服务被android OS()销毁时(如果onDestroy()没有被调用),则通知不会被删除.那么当Android OS本身销毁Service时如何删除通知?
| 归档时间: |
|
| 查看次数: |
2969 次 |
| 最近记录: |