use bundle to save/restore dialog-related ivars. This should fix very

rare crash where class is reloaded (e.g. after long period of non-use)
after being taken down with a dialog in mid-load.  The OS tries to put
the dialog back up but the dialog title string ID, passed to
setTitle() in onCreateDialog(), is 0.
This commit is contained in:
Andy2 2011-07-28 06:42:57 -07:00
parent acafc0a2df
commit 704b08f733

View file

@ -72,6 +72,10 @@ public class BoardActivity extends XWActivity
private static final int CHAT_REQUEST = 1;
private static final int SCREEN_ON_TIME = 10 * 60 * 1000; // 10 mins
private static final String DLG_TITLE = "DLG_TITLE";
private static final String DLG_TITLESTR = "DLG_TITLESTR";
private static final String DLG_BYTES = "DLG_BYTES";
private BoardView m_view;
private int m_jniGamePtr;
private GameUtils.GameLock m_gameLock;
@ -141,7 +145,6 @@ public class BoardActivity extends XWActivity
case DLG_BADWORDS:
case DLG_RETRY:
ab = new AlertDialog.Builder( BoardActivity.this )
//.setIcon( R.drawable.alert_dialog_icon )
.setTitle( m_dlgTitle )
.setMessage( m_dlgBytes )
.setPositiveButton( R.string.button_ok, null );
@ -316,6 +319,7 @@ public class BoardActivity extends XWActivity
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
getBundledData( savedInstanceState );
if ( CommonPrefs.getHideTitleBar( this ) ) {
requestWindowFeature( Window.FEATURE_NO_TITLE );
@ -359,6 +363,24 @@ public class BoardActivity extends XWActivity
loadGame();
}
@Override
protected void onSaveInstanceState( Bundle outState )
{
super.onSaveInstanceState( outState );
outState.putInt( DLG_TITLESTR, m_dlgTitle );
outState.putString( DLG_TITLESTR, m_dlgTitleStr );
outState.putString( DLG_BYTES, m_dlgBytes );
}
private void getBundledData( Bundle bundle )
{
if ( null != bundle ) {
m_dlgTitleStr = bundle.getString( DLG_TITLESTR );
m_dlgTitle = bundle.getInt( DLG_TITLE );
m_dlgBytes = bundle.getString( DLG_BYTES );
}
}
@Override
protected void onActivityResult( int requestCode, int resultCode, Intent data )
{
@ -1238,7 +1260,7 @@ public class BoardActivity extends XWActivity
post( new Runnable() {
public void run() {
showDialog( dlgID ); // crash
showDialog( dlgID );
m_blockingDlgPosted = true;
}
} );