From 6527ebc543b33340989b5e677806e3081323183e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=97=D0=B0=D1=86=D0=B5=D0=BF=D0=B8=D0=BD?= Date: Mon, 19 Nov 2018 20:19:50 +0300 Subject: [PATCH] [android] Fixed crash during setting fragment recovering --- .../settings/BaseXmlSettingsFragment.java | 9 +++++++++ .../maps/settings/SettingsPrefsFragment.java | 19 +++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/android/src/com/mapswithme/maps/settings/BaseXmlSettingsFragment.java b/android/src/com/mapswithme/maps/settings/BaseXmlSettingsFragment.java index d7e6453e57..f94a792f5e 100644 --- a/android/src/com/mapswithme/maps/settings/BaseXmlSettingsFragment.java +++ b/android/src/com/mapswithme/maps/settings/BaseXmlSettingsFragment.java @@ -1,5 +1,6 @@ package com.mapswithme.maps.settings; +import android.content.Context; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.annotation.XmlRes; @@ -11,6 +12,7 @@ import com.mapswithme.maps.R; import com.mapswithme.util.Config; import com.mapswithme.util.ThemeUtils; import com.mapswithme.util.UiUtils; +import com.mapswithme.util.Utils; abstract class BaseXmlSettingsFragment extends PreferenceFragmentCompat { @@ -22,6 +24,13 @@ abstract class BaseXmlSettingsFragment extends PreferenceFragmentCompat setPreferencesFromResource(getXmlResources(), root); } + @Override + public void onAttach(Context context) + { + super.onAttach(context); + Utils.detachFragmentIfCoreNotInitialized(context, this); + } + @Override public void onResume() { diff --git a/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java b/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java index 3afe496536..6bfcce7c57 100644 --- a/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java +++ b/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java @@ -274,11 +274,17 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment return R.xml.prefs_main; } - @Override - public void onCreate(Bundle savedInstanceState) + private boolean onToggleOptOut(Object newValue) { - super.onCreate(savedInstanceState); + boolean isEnabled = (boolean) newValue; + Statistics.INSTANCE.trackSettingsToggle(isEnabled); + return true; + } + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) + { + super.onViewCreated(view, savedInstanceState); mPreferenceScreen = getPreferenceScreen(); mStoragePref = findPreference(getString(R.string.pref_storage)); mPrefEnabled = (TwoStatePreference) findPreference(getString(R.string.pref_tts_enabled)); @@ -309,13 +315,6 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment updateTts(); } - private boolean onToggleOptOut(Object newValue) - { - boolean isEnabled = (boolean) newValue; - Statistics.INSTANCE.trackSettingsToggle(isEnabled); - return true; - } - @Override public void onResume() {