1

I have a main Activity which contains of approximately 90 percent of my app Fragments. After user, logged in on login activity I add the main fragment on onCreate() of the Master Activity.

The issue is when in SettingFragment (which is a PreferenceFragment) i change the locale of the app , I have to recreate the main Activity so on onCreate() it loads the main fragment again which is not desirable (I want to remain on setting with new language).

What is the best way to handle such situation? I have thought of checking SettingFragment visibility from FragmentManager but on recreation it cannot find the settingFragment and it returns always null. Another way might be writing on sharedPreferences to check if MainFragment loaded or not but I am not sure of what's the best state to write or read to.

hotzst
  • 7,238
  • 9
  • 41
  • 64
Shinigami
  • 13
  • 2
  • You should use SharedPreferences for simple things like flags. Check this [guide](http://developer.android.com/guide/topics/data/data-storage.html) with all your options and you'll see why. BTW if no one else writes an answer to your question, you can do so and, after a while, accept it. – Bö macht Blau Feb 04 '16 at 07:17
  • Proper formatting of the question helps readability and increases chances of a good answer. – hotzst Feb 04 '16 at 07:22

1 Answers1

0

You could add android:configChanges="locale" to your activity, then on you fragments you need to overwrite and refresh your UI.

@Override
public void onConfigurationChanged(Configuration newConfig) {
  // refresh your views here
  super.onConfigurationChanged(newConfig);
}
Juampa
  • 2,035
  • 2
  • 25
  • 35