【问题标题】:Build a PendingIntent with a back stack使用返回堆栈构建 PendingIntent
【发布时间】:2018-05-26 21:11:20
【问题描述】:

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

在我的清单文件中,我为每个子活动定义了一个父活动,就像这里描述的 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);

你能帮帮我吗?难道我做错了什么?

【问题讨论】:

    标签: android notifications android-pendingintent back-stack


    【解决方案1】:

    您的代码应该可以正常工作,如下所述: https://developer.android.com/training/notify-user/navigation#java

    确保在相关的清单中定义父活动:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 2020-10-27
      • 2013-09-27
      • 2015-02-09
      • 2022-11-26
      • 1970-01-01
      • 2012-11-23
      相关资源
      最近更新 更多