Android的 - 打开或重新启动应用程序使用活动标志,点击推送通知后, [英] Android - open or restart app after clicking push notification using flag activities

查看:289
本文介绍了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?

推荐答案

您需要设置在意图的意图标志。您可以在通话中被指定它们获得的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的 - 打开或重新启动应用程序使用活动标志,点击推送通知后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆