构建一个带有返回栈的PendingIntent

3
我有三个活动(主页、搜索、目的地),可以用来描述我的UX流程。主页活动是我的启动器活动,然后是搜索活动,它恰好是目的地活动的父活动。所以基本上我想要实现的是有一个通知,它启动目的地活动,然后当我按返回按钮时,我应该回到搜索活动,然后回到主页,但问题是一旦我从目的地活动中按下返回按钮,整个堆栈就会退到后台...
在我的清单文件中,我为每个子活动定义了一个父活动,就像这里描述的那样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);

你能帮我一下吗?我做错了什么吗?

1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接