gpt4 book ai didi

android - 使用返回堆栈构建一个 PendingIntent

转载 作者:行者123 更新时间:2023-12-05 00:06:50 27 4
gpt4 key购买 nike

我有三个 Activity (Home、Search、Destination),我可以用它们来描述我的用户体验流程。 Home Activity 是我的启动器 Activity ,然后是搜索 Activity ,它恰好是 Destination Activity 的父级。所以基本上我想要实现的是有一个通知,它启动 Destination Activity 然后当我按下后退按钮时我应该回到搜索 Activity 然后回到主页,但问题是一旦我从 Destination Activity 中点击后退按钮,整个堆栈进入后台...

在我的 list 文件中,我为每个子 Activity 定义了一个父 Activity ,如此处所述https://developer.android.com/training/notify-user/navigation

这就是我的代码在构建未决 Intent 时的样子:

 // 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

确保在相关 list 中定义父 Activity :

    <activity
android:name=".DetailActivity"
android:parentActivityName=".MainActivity"

关于android - 使用返回堆栈构建一个 PendingIntent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50547032/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com