Fixed the crash on screen rotation
- Fix b/10607566 Change-Id: I078e59af2a76deb272b870d7708ee4148c68590e
This commit is contained in:
@@ -38,12 +38,29 @@ public abstract class LocationSettingsBase extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private static final int LOADER_ID_LOCATION_MODE = 1;
|
private static final int LOADER_ID_LOCATION_MODE = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the fragment is actively running.
|
||||||
|
*/
|
||||||
|
private boolean mActive = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
getLoaderManager().initLoader(LOADER_ID_LOCATION_MODE, null, this);
|
getLoaderManager().initLoader(LOADER_ID_LOCATION_MODE, null, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
mActive = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
mActive = false;
|
||||||
|
}
|
||||||
|
|
||||||
/** Called when location mode has changed. */
|
/** Called when location mode has changed. */
|
||||||
public abstract void onModeChanged(int mode, boolean restricted);
|
public abstract void onModeChanged(int mode, boolean restricted);
|
||||||
|
|
||||||
@@ -61,7 +78,9 @@ public abstract class LocationSettingsBase extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
mode = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE,
|
mode = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE,
|
||||||
Settings.Secure.LOCATION_MODE_OFF);
|
Settings.Secure.LOCATION_MODE_OFF);
|
||||||
onModeChanged(mode, true);
|
if (mActive) {
|
||||||
|
onModeChanged(mode, true);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCATION_MODE, mode);
|
Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCATION_MODE, mode);
|
||||||
@@ -69,9 +88,11 @@ public abstract class LocationSettingsBase extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void refreshLocationMode() {
|
public void refreshLocationMode() {
|
||||||
int mode = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE,
|
if (mActive) {
|
||||||
Settings.Secure.LOCATION_MODE_OFF);
|
int mode = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE,
|
||||||
onModeChanged(mode, isRestricted());
|
Settings.Secure.LOCATION_MODE_OFF);
|
||||||
|
onModeChanged(mode, isRestricted());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user