【发布时间】:2014-04-05 07:44:32
【问题描述】:
我已经测试了大约 4 或 5 天的通知意图。我对自己失望了,我无法达到我的目标。我认为这不是太难,但我无法得到它。单击通知时,我想进行当前的运行活动。我有意使用了很多东西。
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
在pendingIntent中,
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
在清单中,
android:launchMode="singleTop" // android:launchMode="singleTask" // android:launchMode="singleInstance"
但它总是按照我的意图上的课。有人帮助我,我不知道。
【问题讨论】:
-
也许这个 SO link 可能会帮助你。
-
@Halo 你当前的活动名称是什么,notificationIntent 持有哪个活动?
-
MainActivity 是当前活动,Goo.class 在 notificationIntent。
-
好的,那么您不可能打开 mainActivity(因此您的意图应该指向 MainActivity 而不是 Goo 类)并覆盖 mainactivity 中的 onNewIntent() 方法并从中打开 Goo.class。
-
@Halo 我编辑了我的答案,看这里stackoverflow.com/questions/22834790/…
标签: android android-intent notifications android-pendingintent