Skip to content

Commit

Permalink
Fix an update dialog crash issue.
Browse files Browse the repository at this point in the history
Stack trace:

```
Exception a1.h: Bad window token, you cannot show a dialog before an Activity is created or after it's hidden.
    at com.afollestad.materialdialogs.MaterialDialog.show (MaterialDialog.java)
    at com.afollestad.materialdialogs.MaterialDialog$Builder.show (MaterialDialog.java:6)
    at org.mewx.wenku8.async.CheckAppNewVersion.onPostExecute (CheckAppNewVersion.java:225)
    at org.mewx.wenku8.async.CheckAppNewVersion.onPostExecute (CheckAppNewVersion.java:15)
    at android.os.AsyncTask.finish (AsyncTask.java:771)
    at android.os.AsyncTask.access$900 (AsyncTask.java:199)
    at android.os.AsyncTask$InternalHandler.handleMessage (AsyncTask.java:788)
    at android.os.Handler.dispatchMessage (Handler.java:106)
    at android.os.Looper.loopOnce (Looper.java:346)
    at android.os.Looper.loop (Looper.java:475)
    at android.app.ActivityThread.main (ActivityThread.java:7889)
    at java.lang.reflect.Method.invoke
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1009)
```
  • Loading branch information
MewX committed Jul 30, 2024
1 parent f032c99 commit cf615f8
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mewx.wenku8.async;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
Expand Down Expand Up @@ -77,8 +78,10 @@ protected void onPostExecute(Integer code) {
if (verboseMode) {
Toast.makeText(ctx, ctx.getResources().getString(R.string.system_update_latest_version), Toast.LENGTH_SHORT).show();
}
} else {
// update to new version
} else if (ctx instanceof Activity && ((Activity) ctx).hasWindowFocus()) {
// Note that checking window focus is needed: https://stackoverflow.com/a/41118674/4206925

// Update to new version.
new MaterialDialog.Builder(ctx)
.theme(Theme.LIGHT)
.title(R.string.system_update_found_new)
Expand Down

0 comments on commit cf615f8

Please sign in to comment.