我的問題有希望彼此相關。我運行了一個倒數計時器服務,它可以在onfinish方法中引發意圖。完成後,它會自動打開/啓動應用程序,我不希望它執行此操作。爲什麼這樣呢?編號喜歡它只顯示通知。另外,當我點擊通知而不僅僅是恢復活動時,它會創建另一個活動。由於意圖,我認爲問題是相互關聯的。這裏是代碼中斷活動和多個活動問題
從onFinish()從通知
Intent intent = new Intent(BroadcastService.this, MainActivity.class);
intent.putExtra("id1",id1);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
這裏是通知代碼
NotificationCompat.Builder notificBuilder = new NotificationCompat.Builder(this);
notificBuilder.setContentTitle("Loot");
notificBuilder.setContentText("Claim your Gold now!");
notificBuilder.setSmallIcon(R.drawable.gold2);
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notificBuilder.setSound(soundUri);
notificBuilder.setAutoCancel(true);
Intent backhome = new Intent(this, MainActivity.class);
backhome.putExtra("id2",id2);
TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this);
taskStackBuilder.addParentStack(MainActivity.class);
taskStackBuilder.addNextIntent(backhome);
PendingIntent pd = taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
notificBuilder.setContentIntent(pd);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notifID, notificBuilder.build());
isNoteActive = true;
}
你想在'onFinish()'中做什麼?我錯過了這裏的觀點。 –
爲什麼你使用'TaskStackBuilder'作爲'Notification'? –