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.
This commit is contained in:
Eric House 2021-01-03 17:43:28 -08:00
parent bf6afb803f
commit a3048441e9

View file

@ -21,6 +21,8 @@ package org.eehouse.android.xw4;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@ -28,7 +30,6 @@ import org.eehouse.android.xw4.loc.LocUtils;
import java.io.Serializable; import java.io.Serializable;
public class DBAlert extends XWDialogFragment { public class DBAlert extends XWDialogFragment {
private static final String TAG = DBAlert.class.getSimpleName(); private static final String TAG = DBAlert.class.getSimpleName();
private static final String DLG_ID_KEY = "DLG_ID_KEY"; 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 // Assert.failDbg(); // remove: better to see what users will see
dialog = LocUtils.makeAlertBuilder( activity ) dialog = LocUtils.makeAlertBuilder( activity )
.setMessage( "Unable to create " + getDlgID() + " Alert" ) .setMessage( "Unable to create " + getDlgID() + " Alert" )
.setPositiveButton( "Bummer", null ) .setPositiveButton( android.R.string.ok, null )
// .setNegativeButton( "Try now", new OnClickListener() { .setNegativeButton( "Try again", 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 @Override
public void run() { public void onClick( DialogInterface dlg, int button ) {
try { DBAlert alrt = newInstance( mDlgID, mParams );
Activity activity = getActivity(); ((MainActivity)getActivity()).show( alrt );
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 ); .create();
Log.e( TAG, "got ISE; dropping alert" );
}
}
} );
} }
return dialog; return dialog;
} }