本文介绍了Android - 使用标志活动点击推送通知后打开或重新启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Android 中使用推送通知.当我收到推送通知时,如果应用程序仍在运行,我想打开它,否则它应该打开它的一个新实例.

I am using push notifications in Android. When I receive a push notification, I want to open the application if it is still running, else it should open a new instance of it.

我正在使用

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
    Intent.FLAG_ACTIVITY_CLEAR_TOP |
    Intent.FLAG_ACTIVITY_SINGLE_TOP |
    Intent.FLAG_ACTIVITY_NEW_TASK);

但是当我现在收到推送通知并点击它时,什么也没有发生.

But when I receive a push notification now and I click on it, nothing happens.

我怎样才能通过使用 flagIntents 来实现这一点?

How can I still achieve this by using flagIntents?

推荐答案

您需要在 Intent 上设置 Intent 标志.您在调用中指定它们以获取 PendingIntent.试试这个:

You need to set the Intent flags on the Intent. You were specifying them in the call to get a PendingIntent. Try this:

notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
    Intent.FLAG_ACTIVITY_SINGLE_TOP |
    Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
    notificationIntent, 0);

这篇关于Android - 使用标志活动点击推送通知后打开或重新启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 00:57
查看更多