![](/img/trans.png)
[英]Android back-stack not being created from Notification PendingIntent
[英]Build a PendingIntent with a back stack
我有三個活動(主頁,搜索,目標),可以用來描述我的UX流。 主頁活動是我的啟動器活動,然后是搜索活動,它恰好是Destination活動的父級。 因此,基本上我想要實現的是收到一個通知,該通知將啟動Destination活動,然后當我按“后退”按鈕時,我應該返回到Search活動,然后回到Home,但是問題是,一旦我點擊目標活動中的后退按鈕,整個堆棧進入背景...
在清單文件中,我為每個子活動定義了一個父活動,就像這里描述的那樣https://developer.android.com/training/notify-user/navigation
這是構建掛起的意圖時我的代碼的樣子:
// Create an explicit content Intent that starts the main Activity.
Intent notificationIntent = new Intent(this, DestinationActivity.class);
notificationIntent.putExtra("test", destination);
//Intent testIntent = new Intent(this, SearchActivity.class);
notificationIntent.putExtra(DestinationAdapter.DESTINATION, destination);
// notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);
// Construct a task stack.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Push the content Intent onto the stack.
//stackBuilder.addNextIntentWithParentStack(testIntent);
stackBuilder.addNextIntentWithParentStack(notificationIntent);
// Get a PendingIntent containing the entire back stack.
PendingIntent notificationPendingIntent =
stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
你能幫我一下嗎? 難道我做錯了什么?
您的代碼應該可以正常工作,如下所述: https : //developer.android.com/training/notify-user/navigation#java
確保在相關清單中定義父活動:
<activity
android:name=".DetailActivity"
android:parentActivityName=".MainActivity"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.