何かを言う前に、まず質問全体をお読みください。ここで通知が取り消されない
は、通知を作成するための私のコードです: -
public void showNotification(String Name, String Rate, int Image_Source, int PandP, int Repeat) {
remoteview = new RemoteViews(getPackageName(), R.layout.notification_layout);
context = this;
pi = PendingIntent.getActivity(context, 0, new Intent(this, SongsListActivity.class), 0);
P_and_P_I = new Intent("P_and_P_Clicked");
R_I = new Intent("R_Clicked");
N_I = new Intent("N_Clicked");
P_I = new Intent("P_Clicked");
P_and_P_PI = PendingIntent.getBroadcast(context, 1, P_and_P_I, 0);
R_PI = PendingIntent.getBroadcast(context, 2, R_I, 0);
N_PI = PendingIntent.getBroadcast(context, 3, N_I, 0);
P_PI = PendingIntent.getBroadcast(context, 4, P_I, 0);
notification = new NotificationCompat.Builder(this)
.setContent(remoteview)
.setPriority(2)
.setOngoing(true)
.setTicker(NameD.getText())
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(NameD.getText())
.setContentText(RateD.getText())
.setContentIntent(pi)
.setAutoCancel(false)
.setCustomBigContentView(remoteview)
.build();
remoteview.setOnClickPendingIntent(R.id.P_and_P_N, P_and_P_PI);
remoteview.setOnClickPendingIntent(R.id.Repeat_N, R_PI);
remoteview.setOnClickPendingIntent(R.id.Next_N, N_PI);
remoteview.setOnClickPendingIntent(R.id.Previous_N, P_PI);
remoteview.setImageViewResource(R.id.Repeat_N, Repeat);
remoteview.setImageViewResource(R.id.P_and_P_N, PandP);
remoteview.setTextViewText(R.id.Name_N, Name);
remoteview.setTextViewText(R.id.Rate_N, Rate);
remoteview.setImageViewResource(R.id.Image_N, Image_Source);
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(111111, notification);
}
私は、このメソッドを呼び出すことで通知をキャンセルしよう: -
@Override
protected void onDestroy() {
super.onDestroy();
notificationManager.cancelAll();
if(mediaplayer != null)
{
mediaplayer.release();
mediaplayer = null;
mAudioManager.abandonAudioFocus(mOnAudioFocusChangeListener);
}
}
私はこのshowNotificationを複数回使用しますコード。 私はonDestroyが呼び出されていると確信しています。
showNotificationは一度だけ呼ばれる初めにと、アプリが破壊されている場合、その後、通知はをキャンセルしますが、showNotificationはアプリを破壊するには、その後も二回、複数回呼び出されたときに、キャンセルされません。
すべての変数はすべてのメソッドでプログラム全体で公開されています。
そして、私がshowNotificationを呼び出すたびに更新される通知が1つだけ表示されます。
メソッドが複数回呼び出されても通知がキャンセルされるようにするにはどうすればよいですか?
ありがとうございます。