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

[疑惑]:下载文件配合EasyWindow使用,下载完关闭浮窗报错 #202

Closed
hcx1002 opened this issue Sep 22, 2023 · 1 comment
Closed
Labels
question Further information is requested

Comments

@hcx1002
Copy link

hcx1002 commented Sep 22, 2023

问题描述【必填】

下载文件配合EasyWindow使用,下载完关闭浮窗报错,下载中时,悬浮窗的界面数值可以更新,下载完成要关闭浮窗时,却报错。既然下载中界面可以更新,为什么还会报这个错误,尝试了EventBus、AppUpdateWindow里面的handle也是一样的错误

下载文件代码:
`

 EasyHttp.download(lifecycleOwner)
                .method(HttpMethod.GET)
                .file(new File(Utils.getContext().getExternalFilesDir(null), "zds_app_update.apk"))
                .url(url)
                .listener(new OnDownloadListener() {
                    @Override
                    public void onDownloadProgressChange(File file, int progress) {
                        Button button = AppUpdateWindow.getInstance().getContentView().findViewById(R.id.update_button);
                        button.setOnClickListener(null);
                        button.setText("正在更新:"+progress);
                    }

                    @Override
                    public void onDownloadSuccess(File file) {
                        ToastUtils.success("更新下载完成,请点击安装");
                        AppsUtils.installApp(file);
                    }

                    @Override
                    public void onDownloadFail(File file, Exception e) {
                        ToastUtils.error("更新失败,请联系客服!");
                    }

                    @Override
                    public void onDownloadEnd(File file) {
                        AppUpdateWindow.getInstance().cancel();
                    }
                }).start();`

AppUpdateWindow浮窗代码:
`public class AppUpdateWindow extends EasyWindow implements LifecycleOwner {
private static AppUpdateWindow instance;
private final LifecycleRegistry mLifecycle = new LifecycleRegistry(this);

public AppUpdateWindow(Application application) {
    super(application);
    mLifecycle.addObserver(new DefaultLifecycleObserver() {
        @Override
        public void onDestroy(@NonNull LifecycleOwner owner) {
            cancel();
        }
    });
}
public static AppUpdateWindow getInstance() {
    if (instance == null) {
        instance = new AppUpdateWindow(Utils.getContext());
        instance.setGravity(Gravity.CENTER).setOutsideTouchable(false).setBackgroundDimAmount(0.5f).setContentView(R.layout.window_app_update_hint);
    }
    return instance;
}

public void showWindow(String desc, String url) {
    Button button = instance.getContentView().findViewById(R.id.update_button);
    button.setOnClickListener((view) -> {
        LogUtils.d("点击更新" + url);
        AppUpdateApi.downloadApp(this, url);

    });
    TextView viewById = instance.getContentView().findViewById(R.id.update_desc);
    viewById.setText(desc);
    show();
}
@NonNull
@Override
public Lifecycle getLifecycle() {
    return mLifecycle;
}

}`

报错:
App Version:1.0.0(1) OS Version:12(31) Vendor:TAS-AL00(HUAWEI) CPU ABI:arm64-v8a armeabi-v7a armeabi android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:11726) at android.view.ViewRootImpl.doDie(ViewRootImpl.java:9999) at android.view.ViewRootImpl.die(ViewRootImpl.java:9975) at android.view.WindowManagerGlobal.removeViewLocked(WindowManagerGlobal.java:680) at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:614) at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:250) at com.hjq.window.EasyWindow.cancel(EasyWindow.java:892) at vip.huancaixi.zdsroot.api.AppUpdateApi$1.onDownloadEnd(AppUpdateApi.java:60) at com.hjq.http.callback.DownloadCallback.dispatchDownloadSuccessCallback(DownloadCallback.java:201) at com.hjq.http.callback.DownloadCallback.lambda$onResponse$1$com-hjq-http-callback-DownloadCallback(DownloadCallback.java:156) at com.hjq.http.callback.DownloadCallback$$ExternalSyntheticLambda2.run(Unknown Source:2) at android.os.Handler.handleCallback(Handler.java:966) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loopOnce(Looper.java:205) at android.os.Looper.loop(Looper.java:293) at android.app.ActivityThread.main(ActivityThread.java:9685) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:586) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1211)

框架文档是否提及了该问题【必答】

是否已经查阅框架文档但还未能解决的【必答】

issue 列表中是否有人曾提过类似的问题【必答】

是否已经搜索过了 issue 列表但还未能解决的【必答】

@hcx1002 hcx1002 added the question Further information is requested label Sep 22, 2023
@getActivity
Copy link
Owner

小伙子,目前此 issue 打回,原因如下:

  • 这个问题属于 Bug,请勿用疑惑单的 issue 模板进行填写

请重新提交 issue,并且严格按照 issue 模板填写

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants