開始時に通知を作成するサービスがあります。
そして ondestroy() を削除したいです。
.cancel(NOTIFICATION_ID); を使用するだけです。
通常の通知の場合はうまく機能しますが、進行中のイベントを使用している場合はキャンセルされません。
Androidにリソースがある場合、サービスが停止しないことについて何か読んだことがありますが、これを克服するにはどうすればよいですか?
このコードを使用してサービスを開始します
final Intent bg_service = new Intent(BackgroundService.class.getName());
btn_start = (Button)findViewById(R.id.btn_start);
btn_stop = (Button)findViewById(R.id.btn_stop);
btn_start.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startService(bg_service);
}
});
btn_stop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
stopService(bg_service);
}
});
これを作成時に使用します
notificationManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,
"A new notification", System.currentTimeMillis());
notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
Intent intent = new Intent(this, mainapp.class);
PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, "...",
"...", activity);
notificationManager.notify(19314, notification);
そして、これを破壊します
noficationManager.cancel(19314);