2014-09-25 112 views
0

,當我在我的應用程序的時候,我點擊我的應用程序的通知打開另一個我的應用程序,則對第二個屏幕相同的應用程序和BTW我是來自意圖服務創建通知當我點擊通知開我的另一個應用程序

private void sendNotification(String msg, int msgdifferent) { 
    NotificationCompat.Builder mBuilder = 
      new NotificationCompat.Builder(this) 
        .setSmallIcon(R.drawable.ic_launcher) 
        .setContentTitle("......") 
        .setContentText(msg).setContentInfo(msgdifferent + ""); 
    Intent resultIntent = new Intent(this, MainActivity.class); 
    resultIntent.putExtra("Update", "YES"); 
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); 
    stackBuilder.addParentStack(MainActivity.class); 
    stackBuilder.addNextIntent(resultIntent); 
PendingIntent resultPendingIntent = 
      stackBuilder.getPendingIntent(
        0, 
        PendingIntent.FLAG_UPDATE_CURRENT 
      ); 
mBuilder.setContentIntent(resultPendingIntent); 
NotificationManager mNotificationManager = 
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); 
} 

回答

0

你的意思是每個通知都會打開新的活動。所以我覺得你忘了從documentation

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

簡稱添加此步驟,也可以設置您的resultIntent標誌像

resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 
+0

好非常感謝你:) – massaimara98 2014-09-25 18:17:59

+0

如果這是正確的答案,請記住這答案接受 – santalu 2014-09-25 18:20:37

+0

當然,對不起:( – massaimara98 2014-09-25 18:22:50

相關問題