mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-03 23:04:08 +01:00
fix crashes when reloading (rare unless android:configChanges removed
from AndroidManifest.xml). Problem was that managed dialogs are recreated between onStart() and onResume() yet onResume() was where ivars (specifically m_gi) were set. Can't just set them in onStart() because then I'd want to save state them in onStop() which isn't guaranteed to be called. So create a function loadGame() and call it from both, using a flag to prevent its running twice (which flag is cleared in onPause())
This commit is contained in:
parent
3a2af96c24
commit
50c692024b
1 changed files with 120 additions and 88 deletions
|
@ -68,6 +68,8 @@ public class GameConfig extends XWActivity
|
||||||
private static final int CONFIRM_CHANGE_PLAY = PLAYER_EDIT + 3;
|
private static final int CONFIRM_CHANGE_PLAY = PLAYER_EDIT + 3;
|
||||||
private static final int NO_NAME_FOUND = PLAYER_EDIT + 4;
|
private static final int NO_NAME_FOUND = PLAYER_EDIT + 4;
|
||||||
|
|
||||||
|
private static final String WHICH_PLAYER = "WHICH_PLAYER";
|
||||||
|
|
||||||
private CheckBox m_joinPublicCheck;
|
private CheckBox m_joinPublicCheck;
|
||||||
private CheckBox m_gameLockedCheck;
|
private CheckBox m_gameLockedCheck;
|
||||||
private boolean m_isLocked;
|
private boolean m_isLocked;
|
||||||
|
@ -358,6 +360,7 @@ public class GameConfig extends XWActivity
|
||||||
public void onCreate( Bundle savedInstanceState )
|
public void onCreate( Bundle savedInstanceState )
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
getBundledData( savedInstanceState );
|
||||||
|
|
||||||
// 1.5 doesn't have SDK_INT. So parse the string version.
|
// 1.5 doesn't have SDK_INT. So parse the string version.
|
||||||
// int sdk_int = 0;
|
// int sdk_int = 0;
|
||||||
|
@ -391,12 +394,43 @@ public class GameConfig extends XWActivity
|
||||||
setTitle();
|
setTitle();
|
||||||
} // onCreate
|
} // onCreate
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart()
|
||||||
|
{
|
||||||
|
super.onStart();
|
||||||
|
loadGame();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
loadGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause()
|
||||||
|
{
|
||||||
|
if ( null != m_gameLock ) {
|
||||||
|
m_gameLock.unlock();
|
||||||
|
m_gameLock = null;
|
||||||
|
}
|
||||||
|
m_giOrig = null; // flag for onStart and onResume
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState( Bundle outState )
|
||||||
|
{
|
||||||
|
super.onSaveInstanceState( outState );
|
||||||
|
outState.putInt( WHICH_PLAYER, m_whichPlayer );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadGame()
|
||||||
|
{
|
||||||
|
if ( null == m_giOrig ) {
|
||||||
m_giOrig = new CurGameInfo( this );
|
m_giOrig = new CurGameInfo( this );
|
||||||
|
|
||||||
// Lock in case we're going to config. We *could* re-get the
|
// Lock in case we're going to config. We *could* re-get the
|
||||||
// lock once the user decides to make changes. PENDING.
|
// lock once the user decides to make changes. PENDING.
|
||||||
m_gameLock = new GameUtils.GameLock( m_rowid, true ).lock();
|
m_gameLock = new GameUtils.GameLock( m_rowid, true ).lock();
|
||||||
|
@ -481,16 +515,14 @@ public class GameConfig extends XWActivity
|
||||||
check.setOnCheckedChangeListener( lstnr );
|
check.setOnCheckedChangeListener( lstnr );
|
||||||
Utils.setChecked( this, R.id.use_timer, m_gi.timerEnabled );
|
Utils.setChecked( this, R.id.use_timer, m_gi.timerEnabled );
|
||||||
}
|
}
|
||||||
} // onResume
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause()
|
|
||||||
{
|
|
||||||
if ( null != m_gameLock ) {
|
|
||||||
m_gameLock.unlock();
|
|
||||||
m_gameLock = null;
|
|
||||||
}
|
}
|
||||||
super.onPause();
|
} // loadGame
|
||||||
|
|
||||||
|
private void getBundledData( Bundle bundle )
|
||||||
|
{
|
||||||
|
if ( null != bundle ) {
|
||||||
|
m_whichPlayer = bundle.getInt( WHICH_PLAYER );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteCallback interface
|
// DeleteCallback interface
|
||||||
|
|
Loading…
Reference in a new issue