gpt4 book ai didi

android - 向 ComponentInfo 发送广播时出现异常

转载 作者:行者123 更新时间:2023-11-29 00:08:10 30 4
gpt4 key购买 nike

我有一个 Google 云消息的接收器,它已在 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,然后将主要 Activity 滑开,那么如果我发送通知,我会遇到以下崩溃:

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 不知何故崩溃了。当 Activity 被刷走时,PushReceiver 以某种方式死了。如何解决这个问题?

最佳答案

here 中发现同样的问题.似乎是报告的 Android 错误 herehere .

我使用了 here 中的解决方法它对我有用。有人说它有副作用。 side effect

解决方法是在前台服务中启动虚拟 Activity

@Override
public void onTaskRemoved( Intent rootIntent ) {
Intent intent = new Intent( this, ServiceKeepActivity.class );
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}

关于android - 向 ComponentInfo 发送广播时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32291478/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com