Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onScanSuccess 里执行UI操作,不报错,但会导致ANR #38

Closed
lhhseraph opened this issue Aug 29, 2019 · 1 comment
Closed

onScanSuccess 里执行UI操作,不报错,但会导致ANR #38

lhhseraph opened this issue Aug 29, 2019 · 1 comment

Comments

@lhhseraph
Copy link

lhhseraph commented Aug 29, 2019

onScanSuccess 里执行UI操作,不报错,但会导致ANR,里面另起UI线程执行UI操作则没问题

@OverRide
public void onScanSuccess(final String result) {
Log.e("onScanSuccess", result);
mSoundPoolUtil.play();
mScanView.stopScan();

   //不报错,不弹框,执行这个后,按返回  ANR
    new AlertDialog.Builder(ScanActivity.this).setTitle("最新通知").setMessage(result)
            .setCancelable(true).setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialogInterface) {
            mScanView.startScan(); // 显示扫描框,并开始识别
        }
    }).show();

   //不报错,弹框,执行这个后,按返回  正常
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            new AlertDialog.Builder(ScanActivity.this).setTitle("最新通知").setMessage(result)
                    .setCancelable(true).setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    mScanView.startScan(); // 显示扫描框,并开始识别
                }
            }).show();
        }
    });

}

@devilsen
Copy link
Owner

devilsen commented Sep 1, 2019

其实我觉得这样没啥问题,在子线程返回的话有更大的操作空间,可以操作自己需要处理的耗时任务,而且转到主线程的话我的操作和你的也差不多。

@devilsen devilsen closed this as completed Sep 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants