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

BadTokenException (Similar to race condition):未校验登录 View 导致的应用崩溃 #31

Open
liyansong2018 opened this issue Sep 15, 2021 · 0 comments

Comments

@liyansong2018
Copy link

[scenario]
点击“点击头像登录”,此时并不登录;点击“看帖”,出发崩溃

[Analysis]
将要弹出的 dialog(登录)所要依附的 View 已经不存在导致的。

//Ruisi-master/app/src/main/java/me/yluo/ruisiapp/activity/LoginActivity.java
@Override
public void onFailure(Throwable e) {
	AlertDialog dialog = new AlertDialog.Builder(LoginActivity.this)
			.setTitle("加载失败")
			.setMessage("是否重新加载")
			.setPositiveButton("重新加载", (dialogInterface, i) -> loadData())
			.setNegativeButton("关闭", (dialogInterface, i) -> finish())
			.create();
	dialog.show();
}

[Suggestions]

if(!isFinishing()){
	dialog.show();
}

[Log]

beyond1q:/data/system/dropbox # cat [email protected]
Process: me.yluo.ruisiapp
Flags: 0x28c8be44
Package: me.yluo.ruisiapp v40 (2.9.8.2)
Foreground: Yes
Build: samsung/dream2qltezh/dream2qltechn:7.1/N2G48H/G9550ZHU1AQEE:user/release-keys

android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@e6abc7e is not valid; is your activity running?
        at android.view.ViewRootImpl.setView(ViewRootImpl.java:679)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:342)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
        at android.app.Dialog.show(Dialog.java:329)
        at me.yluo.ruisiapp.activity.LoginActivity$4.onFailure(LoginActivity.java:212)
        at me.yluo.ruisiapp.myhttp.ResponseHandler.handleMessage(ResponseHandler.java:60)
        at me.yluo.ruisiapp.myhttp.ResponseHandler.access$000(ResponseHandler.java:13)
        at me.yluo.ruisiapp.myhttp.ResponseHandler$ResponderHandler.handleMessage(ResponseHandler.java:151)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6198)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)
@liyansong2018 liyansong2018 changed the title BadTokenException:未校验登录 View 导致的应用崩溃 BadTokenException (Similar to race condition):未校验登录 View 导致的应用崩溃 Sep 15, 2021
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

1 participant