diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index f0f5136937..b702897ba4 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -112,12 +112,16 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe runOnUiThread(new Runnable() { @Override public void run() { - recreate(); - try { // activity may be destroyed - setUpTabs(true); - } catch (IllegalStateException e) { - log.error("Unhandled exception", e); + if(ev.recreate) { + recreate(); + }else { + try { // activity may be destroyed + setUpTabs(true); + } catch (IllegalStateException e) { + log.error("Unhandled exception", e); + } } + boolean lockScreen = BuildConfig.NSCLIENTOLNY && SP.getBoolean("lockscreen", false); if (lockScreen) getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index ed201d7c97..5a0d84d1f7 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -1,5 +1,6 @@ package info.nightscout.androidaps; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.EditTextPreference; @@ -58,8 +59,9 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre if (key.equals("language")) { String lang = sharedPreferences.getString("language", "en"); LocaleHelper.setLocale(getApplicationContext(), lang); - recreate(); - MainApp.bus().post(new EventRefreshGui()); + MainApp.bus().post(new EventRefreshGui(true)); + //recreate() does not update language so better close settings + finish(); } if (key.equals("short_tabtitles")) { MainApp.bus().post(new EventRefreshGui()); diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventRefreshGui.java b/app/src/main/java/info/nightscout/androidaps/events/EventRefreshGui.java index 1dae34d2af..390ad8ea4f 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventRefreshGui.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventRefreshGui.java @@ -4,4 +4,11 @@ package info.nightscout.androidaps.events; * Created by mike on 13.06.2016. */ public class EventRefreshGui extends Event { + public boolean recreate = false; + public EventRefreshGui(boolean recreate) { + this.recreate = recreate; + } + public EventRefreshGui(){ + this(false); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java b/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java index 8dff2aec93..b5ed76af02 100644 --- a/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java @@ -9,8 +9,12 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.view.ViewGroup; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.ArrayList; +import info.nightscout.androidaps.MainActivity; import info.nightscout.androidaps.interfaces.PluginBase; /** @@ -22,6 +26,8 @@ public class TabPageAdapter extends FragmentStatePagerAdapter { Context context; + private static Logger log = LoggerFactory.getLogger(TabPageAdapter.class); + public TabPageAdapter(FragmentManager fm, Context context) { super(fm); this.context = context; @@ -40,6 +46,8 @@ public class TabPageAdapter extends FragmentStatePagerAdapter { super.finishUpdate(container); } catch (NullPointerException nullPointerException){ System.out.println("Catch the NullPointerException in FragmentStatePagerAdapter.finishUpdate"); + } catch (IllegalStateException e){ + log.error(e.getMessage()); } }