使用反压关闭应用程序后,避免缓存Intent Extras

时间:2016-11-04 13:58:34

标签: android android-intent android-pendingintent

我通过来自通知的PendingIntent启动我的应用,看起来像这样:

PendingIntent pendingIntent = PendingIntent.getActivity
    (getApplicationContext(), 1 , intent, PendingIntent.FLAG_ONE_SHOT);

我设置了一个额外的任务,以便执行特定任务并通过以下方式获取:

GcmListenerService.PushNotificationTrigger pushNotificationTrigger = (GcmListenerService.PushNotificationTrigger) intent.getSerializableExtra(
            GcmListenerService.GCM_PUSH_TRIGGER_KEY);

执行任务后,我通过反压(简单onBackPressed)“关闭”应用程序。再次打开应用程序时,它会再次执行该任务。我调试它并得出结果,pushNotificationTrigger仍然是相同的。 Intent和我关闭它之前有相同的额外内容。在我看来,就像Android缓存它一样。

我已经尝试过的和没有用过的东西:

在第一次阅读之后删除额外内容:

intent.removeExtra(GcmListenerService.GCM_PUSH_TRIGGER_KEY);

用finish()

覆盖onBackPressed

有解决方法吗?

0 个答案:

没有答案
相关问题