gpt4 book ai didi

android - 获取有关点击通知的应用程序运行信息

转载 作者:行者123 更新时间:2023-11-29 01:36:43 25 4
gpt4 key购买 nike

我正在努力获取应用程序在推送通知点击时的流程。

我想要的应用程序流程是有条件的,具体取决于推送通知何时被点击。

因此,当用户点击推送通知时,我想知道我的应用程序是否已经在运行。

如果是,则仅在已运行的应用程序之上显示 Activity A,然后按返回键继续使用之前处于 Activity 状态的同一 Activity 中的旧应用程序。

如果单击通知时应用程序未运行,我想显示 Activity A 和 onBackPress 我想启动 Activity B。

我决定的方法是发送一个带有启动通知的 Intent 的额外参数,但这个额外参数是有条件的。

如何在应用程序中获得这种流程?

最佳答案

您不需要有条件的额外费用。

只需从通知中启动 Activity A。现在,在 Activity A 中添加以下代码:

@Override
public void onBackPressed() {
// If this activity is the only activity in the task, that means the
// app wasn't running when the notification was clicked.
if (isTaskRoot()) {
// Start Activity B
Intent intent = new Intent(this, ActivityB.class);
startActivity(intent);
// NOTE: you should call finish() here if you want Activity A to go away now
// finish();
} else {
// Otherwise, just do the normal BACK stuff (ie: finish this Activity and go
// back to whatever the user was doing in the app)
super.onBackPressed();
}
}

关于android - 获取有关点击通知的应用程序运行信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27484663/

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