getActivity / EasyHttp

Android 网络请求框架,简单易用,so easy
Apache License 2.0
1.38k stars 191 forks source link

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

Closed hcx1002 closed 12 months ago

hcx1002 commented 1 year ago

问题描述【必填】

下载文件配合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 列表但还未能解决的【必答】

getActivity commented 12 months ago

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

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