I have a RuntimeException when I'm trying to open a custom Dialog even though I check if the activity is running.
This is a custom splashscreen and it is triggered on the launching of the app. Everything goes well on the first launch but when my app is into the background and I reopen it, then a crash happens.
I get :
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@e9b1e4 is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:571)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:310)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at android.app.Dialog.show(Dialog.java:319)
at com.mehcode.reactnative.splashscreen.SplashScreen$1.run(SplashScreen.java:23)
and my code looks like this :
private static Dialog mSplashDialog;
/**
* Show the splash screen.
*/
public static void show(final Activity activity) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (!activity.isFinishing()) {
mSplashDialog = new Dialog(activity, R.style.RNSplashScreen_SplashTheme);
mSplashDialog.setCancelable(false);
if (!mSplashDialog.isShowing()) {
mSplashDialog.show();
}
}
}
});
}
Any ideas of what I am missing?
Thanks in advance for your help :)