异常发送广播ComponentInfo时 [英] Exception when sending broadcast to ComponentInfo
问题描述
我对谷歌的云信息的接收器,它注册在AndroidManifest.xml中:
I have a receiver for Google cloud message, it's registered in AndroidManifest.xml:
<receiver
android:name="com.app.android.push.HSPushReceiver"
android:permission="com.google.android.c2dm.permission.SEND"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<action android:name="com.google.android.c2dm.intent.REGISTER" />
<category android:name="com.app.android" />
</intent-filter>
</receiver>
当应用程序是在前台或杀死我可以收到消息。不过,如果我开始通知IntentService,然后轻扫主客场的活动,那么如果我发送一个通知,我得到了以下的崩溃:
I can receive message when the app is in foreground or killed. However, if I start a IntentService with notification and then swipe the main activity away, then if I send a notification, I got the following crash:
08-29 15:29:37.782 W/BroadcastQueue( 757): Exception when sending broadcast to ComponentInfo{com.app.android/com.app.android.push.HSPushReceiver}
08-29 15:29:37.782 W/BroadcastQueue( 757): android.os.DeadObjectException
08-29 15:29:37.782 W/BroadcastQueue( 757): at android.os.BinderProxy.transactNative(Native Method)
08-29 15:29:37.782 W/BroadcastQueue( 757): at android.os.BinderProxy.transact(Binder.java:496)
08-29 15:29:37.782 W/BroadcastQueue( 757): at android.app.ApplicationThreadProxy.scheduleReceiver(ApplicationThreadNative.java:861)
08-29 15:29:37.782 W/BroadcastQueue( 757): at com.android.server.am.BroadcastQueue.processCurBroadcastLocked(BroadcastQueue.java:245)
08-29 15:29:37.782 W/BroadcastQueue( 757): at com.android.server.am.BroadcastQueue.processNextBroadcast(BroadcastQueue.java:898)
08-29 15:29:37.782 W/BroadcastQueue( 757): at com.android.server.am.BroadcastQueue$BroadcastHandler.handleMessage(BroadcastQueue.java:149)
08-29 15:29:37.782 W/BroadcastQueue( 757): at android.os.Handler.dispatchMessage(Handler.java:102)
08-29 15:29:37.782 W/BroadcastQueue( 757): at android.os.Looper.loop(Looper.java:135)
08-29 15:29:37.782 W/BroadcastQueue( 757): at android.os.HandlerThread.run(HandlerThread.java:61)
08-29 15:29:37.782 W/BroadcastQueue( 757): at com.android.server.ServiceThread.run(ServiceThread.java:46)
08-29 15:29:37.782 W/libprocessgroup( 757): failed to open /acct/uid_10377/pid_3948/cgroup.procs: No such file or directory
08-29 15:29:37.785 W/ActivityManager( 757): Scheduling restart of crashed service com.app.android/.HSNotificationService in 578824ms
HSNotificationService莫名其妙地崩溃。不知怎的,当活动被滑开PushReceiver已经死了。如何解决这个问题呢?
HSNotificationService somehow got crashed. Somehow PushReceiver is dead when activity is swiped away. How to resolve this problem?
推荐答案
在<一个发现同样的问题href=\"http://stackoverflow.com/questions/31535891/gcm-push-notification-for-background-app-causes-crash#comment52478944_31535891\">here.似乎是一个Android的bug报告这里和< A HREF =HTTPS://$c$c.google.com/p/android/issues/detail ID = 104308相对=nofollow>这里
Found same problem in here. Seems to be an Android bug reported here and here.
我用的解决方法在这里 >,它的工作对我来说。有人说,它有副作用,但。 副作用
I used the workaround in here and it's working for me. Someone said it has side effect though. side effect
解决方法是在你的前台服务启动一个虚拟活动
The workaround is to start a dummy activity in your foreground service
@Override
public void onTaskRemoved( Intent rootIntent ) {
Intent intent = new Intent( this, ServiceKeepActivity.class );
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
这篇关于异常发送广播ComponentInfo时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!