From a3048441e9d50492042712ed7c25553f8f736df3 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sun, 3 Jan 2021 17:43:28 -0800 Subject: [PATCH] fix the unable-to-post-alert alert Returning null from createDialog() isn't allowed, so return this as a fallback as before. But the old code immediately dismissed it and created another in an infinite loop. So just suck it up and display it. And as always hope users don't see it. --- .../java/org/eehouse/android/xw4/DBAlert.java | 38 +++++-------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBAlert.java index 38e210050..7fe87e0fa 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBAlert.java @@ -21,6 +21,8 @@ package org.eehouse.android.xw4; import android.app.Activity; import android.app.Dialog; +import android.content.DialogInterface.OnClickListener; +import android.content.DialogInterface; import android.os.Bundle; import android.os.Handler; @@ -28,7 +30,6 @@ import org.eehouse.android.xw4.loc.LocUtils; import java.io.Serializable; - public class DBAlert extends XWDialogFragment { private static final String TAG = DBAlert.class.getSimpleName(); private static final String DLG_ID_KEY = "DLG_ID_KEY"; @@ -102,34 +103,15 @@ public class DBAlert extends XWDialogFragment { // Assert.failDbg(); // remove: better to see what users will see dialog = LocUtils.makeAlertBuilder( activity ) .setMessage( "Unable to create " + getDlgID() + " Alert" ) - .setPositiveButton( "Bummer", null ) - // .setNegativeButton( "Try now", new OnClickListener() { - // @Override - // public void onClick( DialogInterface dlg, int button ) { - // DBAlert alrt = newInstance( mDlgID, mParams ); - // ((MainActivity)getActivity()).show( alrt ); - // } - // }) - .create(); - - new Handler().post( new Runnable() { - @Override - public void run() { - try { - Activity activity = getActivity(); - if ( null != activity && activity instanceof MainActivity ) { - DBAlert newMe = newInstance( getDlgID(), mParams ); - ((MainActivity)activity).show( newMe ); - dismiss(); // kill myself... - } else { - Log.d( TAG, "null activity..." ); - } - } catch ( IllegalStateException ex ) { - // Assert.assertFalse( BuildConfig.DEBUG ); - Log.e( TAG, "got ISE; dropping alert" ); + .setPositiveButton( android.R.string.ok, null ) + .setNegativeButton( "Try again", new OnClickListener() { + @Override + public void onClick( DialogInterface dlg, int button ) { + DBAlert alrt = newInstance( mDlgID, mParams ); + ((MainActivity)getActivity()).show( alrt ); } - } - } ); + }) + .create(); } return dialog; }