發射活動後,我啓動從notification
我收到activity
。如果notification
被按下,它將啓動一個activity
。如果有對back-stack
沒有以前activities
,或者只有某一個,我想刪除某些activity
,並在那裏,比新活動插入我的主要activity
。讓我們回到主要活動從通知
我發現這個Thread,但我不明白他怎麼有兩個意圖和標誌處理它。
即intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK)
是否明智做到這一點,他做到了,或者我應該編輯該活動堆棧的方式嗎?
我對android開發相當新,所以有些建議可以幫助我。 非常感謝;)
更新:所以我去了stackbuilder,但不知何故它沒有設置正確...我沒有找到我的錯誤,我的布爾noActivity肯定設置,但我想某種方式我誤解了堆棧如何將之前的活動放在那裏。
private void sendNotification(messageType type, Map<String, String> data, boolean noActivities) {
Intent i;
String message = "";
switch (type) {
case newFOLLOWER:
User cur = new User(data.get("other.name"));
User.lookAT = User.getOtherUserByName(cur);
i = new Intent(this, other_profile.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
message = data.get("other.name") + " is following you now. Click to see his profile";
i.putExtra("Notification", data.get("other.name") + " is following you now. Click to see his profile");
break;
default:
i = null;
break;
}
if (i != null) {
TaskStackBuilder stack = TaskStackBuilder.create(this);
if(noActivities){
stack.addParentStack(Photostream.class);
}
stack.addNextIntent(i);
PendingIntent pendingIntent = stack.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);//PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("PIC LOC")
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSound)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
更新2:所以搜索了很多,我發現,我missunderstood堆棧生成器的工作原理之後。我發現另一個線程,他們描述瞭如何添加工作。 Editing the Manifest in order to have a previous stack。 我快和你跳給我提供了非常和善教程的一部分......
感謝您的幫助球員;)