我在Android中使用推送通知。当我收到推送通知时,我想打开应用程序,如果它仍在运行,否则它应该打开它的新实例。
我在用
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
但是当我现在收到推送通知并点击它时,没有任何反应。
我怎样才能通过使用flagIntents实现这一目标?
你需要在上面设置Intent标志 Intent
。您在调用中指定了它们以获取a PendingIntent
。尝试这个:
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);
你需要在上面设置Intent标志 Intent
。您在调用中指定了它们以获取a PendingIntent
。尝试这个:
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 Mainfest文件中设置以下内容
android:noHistory="true"
android:launchMode = "singleTop"