活动后退堆栈按钮来自推送意图

时间:2016-09-12 19:08:34

标签: android android-intent

当我点击推送通知(来自我的应用),意图触发和打开消息活动。 但是以这种方式返回堆栈箭头关闭应用程序。如何在后台堆栈中添加适当的活动/用于返回上一个活动的标志(不是关闭应用程序),是否需要覆盖OnNewIntent()?

由于

1 个答案:

答案 0 :(得分:1)

您可以在清单中为深度链接的活动添加父级,也可以在启动活动时添加后退状态。

清单:

<application ... >
...
<!-- The main/home activity (it has no parent activity) -->
<activity
    android:name="com.example.myfirstapp.MainActivity" ...>
    ...
</activity>
<!-- A child of the main activity -->
<activity
    android:name="com.example.myfirstapp.DisplayMessageActivity"
    android:label="@string/title_activity_display_message"
    android:parentActivityName="com.example.myfirstapp.MainActivity" >
    <!-- The meta-data element is needed for versions lower than 4.1 -->
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.example.myfirstapp.MainActivity" />
</activity>

爪哇:

// Intent for the activity to open when user selects the notification
Intent detailsIntent = new Intent(this, DetailsActivity.class);

// Use TaskStackBuilder to build the back stack and get the PendingIntent
PendingIntent pendingIntent =
        TaskStackBuilder.create(this)
                        // add all of DetailsActivity's parents to the stack,
                        // followed by DetailsActivity itself
                        .addNextIntentWithParentStack(upIntent)
                        .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentIntent(pendingIntent);

参考:https://developer.android.com/training/implementing-navigation/temporal.html