为什么广播接收器仅在华为设备上引起ANR? [英] Why Broadcast Receiver is causing ANR on only Huawei Devices?

查看:259
本文介绍了为什么广播接收器仅在华为设备上引起ANR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个广播接收器(已声明清单),它可以监听意图并启动jobIntentService。由于jobIntentService使用的是工作线程,并且Broadcast Receiver没有任何繁重的操作(它仅接收意图并调用jobIntentService)。广播接收器中不应有任何ANR原因。另外,我仅在华为设备上获得ANR。

I have a broadcast receiver(Manifest declared) that listens to an intent and starts the jobIntentService. Since jobIntentService is using Worker Threads and Broadcast Receiver does not have any heavy operations (It just receives the intent and calls the jobIntentService). There shouldn't be any reasons for ANRs in the broadcast receiver. Also, I'm getting ANRs only on Huawei devices.

这是我的广播接收方代码:

Here's my code for broadcast receiver:

public class SessionReceiver extends BroadcastReceiver {
    private static final String TAG = "SessionReceiver";
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction() == null) return;
        Log.d(TAG, "onReceive: called");
        SessionChangeService.enqueueWork(context, intent);
    }
}

如您所见,我只是将广播中的工作加入队列

As you can see, I'm only enqueuing the work in the broadcast receiver but I'm still getting ANRs on Huawei devices.

清单声明:

<receiver
    android:name=".receivers.SessionReceiver"
    android:enabled="true"
    android:exported="true">
    <intent-filter>
        <action android:name="android.media.action.OPEN_AUDIO_EFFECT_CONTROL_SESSION" />
        <action android:name="android.media.action.CLOSE_AUDIO_EFFECT_CONTROL_SESSION" />
    </intent-filter>
</receiver>

JobIntentService:

JobIntentService:

public class SessionChangeService extends JobIntentService {
    private static final String TAG = "SessionChangeService";

    public static void enqueueWork(Context context, Intent intent) {
        Log.d(TAG, "enqueueWork: enqueued");
        enqueueWork(context, SessionChangeService.class, Constants.SESSION_CHANGE_JOB_ID, intent);
    }

    @Override
    protected void onHandleWork(@NonNull Intent intent) {
           //...work...
    }
}

ANR日志为:

Broadcast of Intent { act=android.media.action.CLOSE_AUDIO_EFFECT_CONTROL_SESSION flg=0x2030 pkg=/.receivers.SessionReceiver (has extras) }

任何帮助将不胜感激。

推荐答案

基于以上分析,此问题与SessionReceiver无关,但应是应用程序导航/ UI中阻止主线程的内容。
在主线程被阻塞的情况下,广播接收器也将在主线程中被阻塞,并最终导致ANR。

Based on the above analyses, this issue is not related to SessionReceiver but should be something in the app navigations/ UI that blocks the main thread. With the main thread blocked, broadcast receivers will also be blocked in the main thread and finally cause ANR.

这篇关于为什么广播接收器仅在华为设备上引起ANR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆