2012-04-03 13 views
4

通知バーに異なる通知を送信しています。アクティビティが完了したときの通知を避ける方法

すべてが異なるIDを持っていますが、その意図は同じアクティビティをターゲットにしています。

最初の通知をクリックすると、アクティビティが開始され、その終了がクリックされました。

私の活動が終了すると、バーの残りの通知はすべて消えています。

通知バーに残しておきたい。

これを実現する方法。

ここにコードがあります。事前に

 mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
         int id = 10; 
         notificationIntent = new Intent(context, MyAct.class); // creating intent. 
         notificationIntent.putExtra("data", data); 
         notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);   

         // defining actions while notification. 
         contentIntent = PendingIntent.getActivity(context, id,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);    
         notification = new Notification(R.drawable.icon, message, 
           System.currentTimeMillis()); 
         notification.setLatestEventInfo(context, "Hello", message, 
           contentIntent); 

         notification.defaults |= Notification.DEFAULT_VIBRATE; 
         notification.defaults |= Notification.DEFAULT_LIGHTS; 
         notification.defaults |= Notification.DEFAULT_SOUND; 
         mNotificationManager.notify(id, notification); 
         id++; 

おかげで....!

答えて

3

の方法onNewIntent上のステータスバーに通知を追加することで試すことができます。

 android:launchMode="singleTask" 
     android:taskAffinity="" 
     android:excludeFromRecents="true" 
0

通知が正しく作成されていないようです。 Notification.Builderクラスのjavadocを再読み込みして、間違ったことを確認することをお勧めします。 setAutoCancel()を呼び出すことを怠ったか、同じオブジェクトを再利用して通知を投稿した可能性があります。

+0

idのアクティビティベースの通知を手動で取り消しています。 – Noby

関連する問題