Fixed crash when changing settings
Looking at Fragment1, clicking Fragment2 Fragment2.onCreate Fragment2.onResume Fragment1.onPause <- This sets PreferenceUI to Fragment1, so onClickListeners in Fragment2 now have a reference to the wrong fragment
This commit is contained in:
parent
94bf3cd734
commit
9d3d92cc9d
|
@ -113,16 +113,18 @@ public class PreferenceActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MainFragment extends PreferenceFragment {
|
public static class MainFragment extends PreferenceFragment {
|
||||||
|
private int screen;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setRetainInstance(true);
|
setRetainInstance(true);
|
||||||
addPreferencesFromResource(getArguments().getInt(PARAM_RESOURCE));
|
screen = getArguments().getInt(PARAM_RESOURCE);
|
||||||
|
addPreferencesFromResource(screen);
|
||||||
PreferenceActivity activity = instance.get();
|
PreferenceActivity activity = instance.get();
|
||||||
if (activity != null && activity.preferenceController != null) {
|
if (activity != null && activity.preferenceController != null) {
|
||||||
activity.preferenceUI.setFragment(this);
|
activity.preferenceUI.setFragment(this);
|
||||||
activity.preferenceController.onCreate(getArguments().getInt(PARAM_RESOURCE));
|
activity.preferenceController.onCreate(screen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,9 +133,9 @@ public class PreferenceActivity extends AppCompatActivity {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
PreferenceActivity activity = instance.get();
|
PreferenceActivity activity = instance.get();
|
||||||
if(activity != null && activity.preferenceController != null) {
|
if(activity != null && activity.preferenceController != null) {
|
||||||
activity.setTitle(getTitle(getArguments().getInt(PARAM_RESOURCE)));
|
activity.setTitle(getTitle(screen));
|
||||||
activity.preferenceUI.setFragment(this);
|
activity.preferenceUI.setFragment(this);
|
||||||
activity.preferenceController.onResume(getArguments().getInt(PARAM_RESOURCE));
|
activity.preferenceController.onResume(screen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,9 +161,8 @@ public class PreferenceActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
PreferenceActivity activity = instance.get();
|
PreferenceActivity activity = instance.get();
|
||||||
if(activity != null && activity.preferenceController != null) {
|
if (screen == R.xml.preferences_integrations) {
|
||||||
activity.preferenceUI.setFragment(this);
|
activity.preferenceController.unregisterGpodnet();
|
||||||
activity.preferenceController.onPause(getArguments().getInt(PARAM_RESOURCE));
|
|
||||||
}
|
}
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
@ -169,9 +170,8 @@ public class PreferenceActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
PreferenceActivity activity = instance.get();
|
PreferenceActivity activity = instance.get();
|
||||||
if(activity != null && activity.preferenceController != null) {
|
if (screen == R.xml.preferences_storage) {
|
||||||
activity.preferenceUI.setFragment(this);
|
activity.preferenceController.unsubscribeExportSubscription();
|
||||||
activity.preferenceController.onStop();
|
|
||||||
}
|
}
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -638,13 +638,11 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPause(int screen) {
|
public void unregisterGpodnet() {
|
||||||
if (screen == R.xml.preferences_integrations) {
|
|
||||||
GpodnetPreferences.unregisterOnSharedPreferenceChangeListener(gpoddernetListener);
|
GpodnetPreferences.unregisterOnSharedPreferenceChangeListener(gpoddernetListener);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void onStop() {
|
public void unsubscribeExportSubscription() {
|
||||||
if (subscription != null) {
|
if (subscription != null) {
|
||||||
subscription.unsubscribe();
|
subscription.unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue