我为我的问题寻找解决方案但找不到任何东西。我的应用程序正在使用GCM,我发送的一些推送是错误的(有时Intent的数据没有更新,它与前一个相同)。
我使用以下有效负载发送推送通知:
{
"registration_ids" : ["dS9iBOAXlWc:APA9..."],
"notification" : {
"title" : "Hey",
"body" : "This is the body"
},
"data" : {
// my data
}
}
当应用程序在后台时,系统会生成通知,这就是我想要的。我以这种方式处理数据:
public class MyActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {
@Override
public void onActivityResumed(Activity activity) {
Intent activityIntent = activity.getIntent();
if (null != activityIntent && null != activityIntent.getExtras()) {
// process activityIntent.getExtras();
}
}
}
除了一组特定的事件外,一切都运作良好:
如何清除此意图?并让GCM Receiver更新它吗?
经过更多研究,它看起来真的像FCM或Android的bug。 当我的应用程序在后台并单击通知时,会创建一个新的活动。但按照我描述的步骤,恢复了相同的活动:
杀死后,点击通知点击:11-16 10:10:35.434 24132-24132/com.zinfroy.intentstest W/ActivityLifecycle: onActivityCreated: com.zinfroy.intentstest.MainActivity@c14c125
11-16 10:10:35.517 24132-24132/com.zinfroy.intentstest D/MainActivity#onCreate: Key: google.message_id Value: 0:1479287431249234%162dc7d9162dc7d9
11-16 10:10:35.521 24132-24132/com.zinfroy.intentstest W/ActivityLifecycle: onActivityStarted: com.zinfroy.intentstest.MainActivity@c14c125
11-16 10:10:35.522 24132-24132/com.zinfroy.intentstest D/ActivityLifecycle#onStarted: Key: google.message_id Value: 0:1479287431249234%162dc7d9162dc7d9
11-16 10:10:35.525 24132-24132/com.zinfroy.intentstest W/ActivityLifecycle: onActivityResumed: com.zinfroy.intentstest.MainActivity@c14c125
11-16 10:10:35.525 24132-24132/com.zinfroy.intentstest D/ActivityLifecycle#onResumed: Key: google.message_id Value: 0:1479287431249234%162dc7d9162dc7d9
11-16 10:10:35.526 24132-24132/com.zinfroy.intentstest D/MainActivity#onResume: Key: google.message_id Value: 0:1479287431249234%162dc7d9162dc7d9
点击主页按钮:
11-16 10:13:12.366 24132-24132/com.zinfroy.intentstest W/ActivityLifecycle: onActivityPaused: com.zinfroy.intentstest.MainActivity@c14c125
11-16 10:13:12.406 24132-24132/com.zinfroy.intentstest W/ActivityLifecycle: onActivitySaveInstanceState: com.zinfroy.intentstest.MainActivity@c14c125
11-16 10:13:12.406 24132-24132/com.zinfroy.intentstest D/ActivityLifecycle#saveInstance: Key: com.google.firebase.analytics.screen_service Value: Bundle[{referrer_name=MainActivity, id=-7274484894154241509, name=null}]
11-16 10:13:12.408 24132-24132/com.zinfroy.intentstest W/ActivityLifecycle: onActivityStopped: com.zinfroy.intentstest.MainActivity@c14c125
点击通知:
这里没有onActivityCreated
!
11-16 10:13:22.342 24132-24132/com.zinfroy.intentstest W/ActivityLifecycle: onActivityStarted: com.zinfroy.intentstest.MainActivity@c14c125
11-16 10:13:22.342 24132-24132/com.zinfroy.intentstest D/ActivityLifecycle#onStarted: Key: google.message_id Value: 0:1479287431249234%162dc7d9162dc7d9
11-16 10:13:22.342 24132-24132/com.zinfroy.intentstest W/ActivityLifecycle: onActivityResumed: com.zinfroy.intentstest.MainActivity@c14c125
11-16 10:13:22.343 24132-24132/com.zinfroy.intentstest D/ActivityLifecycle#onResumed: Key: google.message_id Value: 0:1479287431249234%162dc7d9162dc7d9
11-16 10:13:22.344 24132-24132/com.zinfroy.intentstest D/MainActivity#onResume: Key: google.message_id Value: 0:1479287431249234%162dc7d9162dc7d9
因此,当恢复相同的Activity时,会读取相同的Intent:/