Skip to content

Commit

Permalink
bugfix: PathPreference dialog retains state on rotation.
Browse files Browse the repository at this point in the history
Pulled my hair out on this one, and it's still kind of a hack...
Unbelievably difficult to do the simplest of things sometimes.
  • Loading branch information
littleguy77 committed Jan 18, 2013
1 parent 8cb7f9d commit abb57a0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/paulscode/android/mupen64plusae/persistent/PathPreference.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.os.Environment;
import android.os.Parcelable;
import android.preference.DialogPreference;
import android.text.TextUtils;
import android.util.AttributeSet;
Expand Down Expand Up @@ -166,6 +167,37 @@ else if( mDoReclick )
}
}

@Override
protected Parcelable onSaveInstanceState()
{
final SavedStringState myState = new SavedStringState( super.onSaveInstanceState() );
myState.mValue = mNewValue;
return myState;
}

@Override
protected void onRestoreInstanceState( Parcelable state )
{
if( state == null || !state.getClass().equals( SavedStringState.class ) )
{
// Didn't save state for us in onSaveInstanceState
super.onRestoreInstanceState( state );
return;
}

final SavedStringState myState = (SavedStringState) state;
super.onRestoreInstanceState( myState.getSuperState() );
populate( myState.mValue );

// If the dialog is already showing, we must close and reopen to refresh the contents
// TODO: Find a less hackish solution, if one exists
if( getDialog() != null )
{
mDoReclick = true;
getDialog().dismiss();
}
}

private void populate( String path )
{
// Cache the path to persist on Ok
Expand Down

0 comments on commit abb57a0

Please sign in to comment.