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

Singleton DialogManager break the library #6

Closed
devnied opened this issue Aug 30, 2018 · 1 comment
Closed

Singleton DialogManager break the library #6

devnied opened this issue Aug 30, 2018 · 1 comment
Assignees
Labels

Comments

@devnied
Copy link

devnied commented Aug 30, 2018

When we want to show the rate dialog in multiple Activity or in the same activity, if the first activity that call AppRate.showRateDialogIfMeetsConditions(this); is destroyed. The next call will fail with:

java.lang.RuntimeException: Unable to resume activity {xxx/xxx.HomeActivity}: android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@b857bc1 is not valid; is your activity running?
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3454)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3494)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2757)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1496)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6186)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
     Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@b857bc1 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:94)
        at android.app.Dialog.show(Dialog.java:329)
        at com.vorlonsoft.android.rate.AppRate.showRateDialog(AppRate.java:413)
        at com.vorlonsoft.android.rate.AppRate.showRateDialogIfMeetsConditions(AppRate.java:114)
        at xxx.activity.HomeActivity.onResume(HomeActivity.java:411)
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1270)
        at android.app.Activity.performResume(Activity.java:6788)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3431)

The DialogManager Singleton hold the first activity as context and reuse it even it was destroyed.

If you want to keep the singleton, I think the createDialogManager function must check if the singleton context is not destroyed before reuse it.

This issue is linked to #5.
ps: I have tested with the version 1.1.9 and with the latest commit into the master branch.
Thanks,

@AlexanderLS
Copy link
Member

Hi @devnied,

Thank you!

It's my mistake. I was so sure that it was Application Context that I didn't even look at the code. Key moment - it's Activity Context, not Application Context.

Fixed in LIBbb20831

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

No branches or pull requests

2 participants