GCM push notification for background app causes crash

微笑、不失礼 提交于 2019-12-20 04:15:28

问题


I stumbled about a problem to receive GCM messages if my app runs in background (Service). In my scenario, I don't receive the GCM message (please notice it is not about how to receive GCM in general like here) and the ActivityManager kills the app. So I wonder if I have a conceptual misunderstanding or if it is a general problem.

Background

I have an Android application that runs in foreground (Activity) and background (Service). The application is attached to a persistent notification to make sure that the app continues to run even if the user opens the Android TaskManager and swipes the App away. The app uses a WakefulBroadcastReceiver and an IntentService to receives and processes GCM messages (both are registered in the manifest file and all permissions are set). As far as I understand this was the suggested pattern by Google to process GCM messages. Similar solutions can be seen here or here but if required I can add code examples too. I know that Google changed the Android BroadcastReceiver flow with API 3.1 (e.g. here). In general I am able to receive and process GCM messages if my app is in foreground or simply in background (while the activity still exists).

Error scenario

  1. User starts the application
  2. User opens the Android task manager
  3. User swipes / removes the application from the task manager (notice: the app service is still running in the background. Everything my app does in the background works fine and the persistent notification of the app is still available)
  4. GCM push notification will be send to the device/app.
  5. My WakefulBroadcastReceiver doesn't get the push notification. Also on some devices, the app dies (the persistent notification will be removed too). On my test-device I noticed the following log from logcat while the persistent notification stays, but my app seemed to be not running anymore (no further log entries of the app in logcat): 07-20 12:46:36.930: I/GCM(1071): GCM message foo.bar.blub 0:14373891986... 07-20 12:46:36.940: I/ActivityManager(750): Killing 23750:foo.bar.blub/... (adj 0): remove task There are some information available, that an application can't process GCM messages if the app was forced-quit (e.g. here or this) but this is not my case. My app runs in the background, only the activity is removed. When the error scenario occurs, no additianal exception stacktraces of my app are available. I don't see a reason why I don't receive the GCM message or even why the app get's killed.

The same error happens if I register the WakefulBroadcastReceiver within the service that is attached to the persistent notification.

Additional information

Google announced a new way to process GCM messages and encourages users to change. For some reasons I can't switch short-termed to the new way. Due to this I haven't verified the new suggested way.

EDIT: Additional Log-Informations while switching to the GcmReceiver:

08-06 18:33:01.670: I/GCM(3360): GCM message foo.bar.blub 0:1438878778919403%9002042af9fd7ecd 08-06 18:33:01.695: I/ActivityManager(815): Killing 4296:foo.bar.blub/u0a216 (adj 0): remove task ... 08-06 18:33:01.909: W/BroadcastQueue(815): Exception when sending broadcast to ComponentInfo{foo.bar.blub/com.google.android.gms.gcm.GcmReceiver} 08-06 18:33:01.909: W/BroadcastQueue(815): android.os.DeadObjectException 08-06 18:33:01.909: W/BroadcastQueue(815): at android.os.BinderProxy.transactNative(Native Method) 08-06 18:33:01.909: W/BroadcastQueue(815): at android.os.BinderProxy.transact(Binder.java:496) 08-06 18:33:01.909: W/BroadcastQueue(815): at android.app.ApplicationThreadProxy.scheduleReceiver(ApplicationThreadNative.java:861) 08-06 18:33:01.909: W/BroadcastQueue(815): at com.android.server.am.BroadcastQueue.processCurBroadcastLocked(BroadcastQueue.java:245) 08-06 18:33:01.909: W/BroadcastQueue(815): at com.android.server.am.BroadcastQueue.processNextBroadcast(BroadcastQueue.java:898) 08-06 18:33:01.909: W/BroadcastQueue(815): at com.android.server.am.BroadcastQueue$BroadcastHandler.handleMessage(BroadcastQueue.java:149) 08-06 18:33:01.909: W/BroadcastQueue(815): at android.os.Handler.dispatchMessage(Handler.java:102) 08-06 18:33:01.909: W/BroadcastQueue(815): at android.os.Looper.loop(Looper.java:135) 08-06 18:33:01.909: W/BroadcastQueue(815): at android.os.HandlerThread.run(HandlerThread.java:61) 08-06 18:33:01.909: W/BroadcastQueue(815): at com.android.server.ServiceThread.run(ServiceThread.java:46) 08-06 18:33:01.909: W/libprocessgroup(815): failed to open /acct/uid_10216/pid_4296/cgroup.procs: No such file or directory 08-06 18:33:01.910: W/ActivityManager(815): Scheduling restart of crashed service foo.bar.blub/.service.BubbleService in 1000ms 08-06 18:33:01.958: W/ActivityManager(815): Spurious death for ProcessRecord{26174c48 4412:foo.bar.blub/u0a216}, curProc for 4296: null 08-06 18:33:03.253: W/ctxmgr(28358): [PowerConnectionState]Got same value as before for power connection (Plug state: 2 BatteryLevel: 0.66) 08-06 18:33:08.277: W/ctxmgr(28358): [PowerConnectionState]Got same value as before for power connection (Plug state: 2 BatteryLevel: 0.66)

08-06 18:33:01.909: W/libprocessgroup(815): failed to open /acct/uid_10216/pid_4296/cgroup.procs: No such file or directory 08-06 18:33:01.910: W/ActivityManager(815): Scheduling restart of crashed service foo.bar.blub/.service.BubbleService in 1000ms 08-06 18:33:01.957: I/art(4412): Late-enabling -Xcheck:jni 08-06 18:33:01.958: I/ActivityManager(815): Start proc 4412:foo.bar.blub/u0a216 for broadcast foo.bar.blub/com.google.android.gms.gcm.GcmReceiver 08-06 18:33:01.958: W/ActivityManager(815): Spurious death for ProcessRecord{26174c48 4412:foo.bar.blub/u0a216}, curProc for 4296: null 08-06 18:33:01.992: I/art(4412): Debugger is no longer active 08-06 18:33:02.024: I/GcmDataIntentService(4412): Push message to process: .................

Did someone else encounter the problem and found a solution? :-) Or is my understanding wrong?

Thanks!


回答1:


This problem will still occur with the new suggested way of Google (using a GcmReceiver (com.google.android.gms.gcm.GcmReceiver) and a GcmListenerService). The general problem seems to correlate to this bug. Maybe the mentioned workarounds are useful to someone.



来源:https://stackoverflow.com/questions/31535891/gcm-push-notification-for-background-app-causes-crash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!