Merge pull request #574 from MilosKozak/illegalstate-fix
illegalState crash fix
This commit is contained in:
commit
28a52b3ab7
4 changed files with 28 additions and 7 deletions
|
@ -112,12 +112,16 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if(ev.recreate) {
|
||||||
recreate();
|
recreate();
|
||||||
|
}else {
|
||||||
try { // activity may be destroyed
|
try { // activity may be destroyed
|
||||||
setUpTabs(true);
|
setUpTabs(true);
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
boolean lockScreen = BuildConfig.NSCLIENTOLNY && SP.getBoolean("lockscreen", false);
|
boolean lockScreen = BuildConfig.NSCLIENTOLNY && SP.getBoolean("lockscreen", false);
|
||||||
if (lockScreen)
|
if (lockScreen)
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.nightscout.androidaps;
|
package info.nightscout.androidaps;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
|
@ -58,8 +59,9 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
if (key.equals("language")) {
|
if (key.equals("language")) {
|
||||||
String lang = sharedPreferences.getString("language", "en");
|
String lang = sharedPreferences.getString("language", "en");
|
||||||
LocaleHelper.setLocale(getApplicationContext(), lang);
|
LocaleHelper.setLocale(getApplicationContext(), lang);
|
||||||
recreate();
|
MainApp.bus().post(new EventRefreshGui(true));
|
||||||
MainApp.bus().post(new EventRefreshGui());
|
//recreate() does not update language so better close settings
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
if (key.equals("short_tabtitles")) {
|
if (key.equals("short_tabtitles")) {
|
||||||
MainApp.bus().post(new EventRefreshGui());
|
MainApp.bus().post(new EventRefreshGui());
|
||||||
|
|
|
@ -4,4 +4,11 @@ package info.nightscout.androidaps.events;
|
||||||
* Created by mike on 13.06.2016.
|
* Created by mike on 13.06.2016.
|
||||||
*/
|
*/
|
||||||
public class EventRefreshGui extends Event {
|
public class EventRefreshGui extends Event {
|
||||||
|
public boolean recreate = false;
|
||||||
|
public EventRefreshGui(boolean recreate) {
|
||||||
|
this.recreate = recreate;
|
||||||
|
}
|
||||||
|
public EventRefreshGui(){
|
||||||
|
this(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,12 @@ import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainActivity;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,6 +26,8 @@ public class TabPageAdapter extends FragmentStatePagerAdapter {
|
||||||
|
|
||||||
Context context;
|
Context context;
|
||||||
|
|
||||||
|
private static Logger log = LoggerFactory.getLogger(TabPageAdapter.class);
|
||||||
|
|
||||||
public TabPageAdapter(FragmentManager fm, Context context) {
|
public TabPageAdapter(FragmentManager fm, Context context) {
|
||||||
super(fm);
|
super(fm);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
@ -40,6 +46,8 @@ public class TabPageAdapter extends FragmentStatePagerAdapter {
|
||||||
super.finishUpdate(container);
|
super.finishUpdate(container);
|
||||||
} catch (NullPointerException nullPointerException){
|
} catch (NullPointerException nullPointerException){
|
||||||
System.out.println("Catch the NullPointerException in FragmentStatePagerAdapter.finishUpdate");
|
System.out.println("Catch the NullPointerException in FragmentStatePagerAdapter.finishUpdate");
|
||||||
|
} catch (IllegalStateException e){
|
||||||
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue