Actionbarsherlock Restart To Apply Theme Triggers Wrong Lifecycle Methods
I use a SherlockFragmentActivity with 3 tabs. Each of these tabs are containing a SherlockFragment. If I restart my app (to apply a theme) with this code: (thanks to Dante!) finish
Solution 1:
You have to save the value somewhere,for example in the database or in the shared preferences.
Before you apply the setTheme(THEME);
You have to retrieve that value.
This is the initial value:
publicstaticint THEME = R.style.Theme_Sherlock;
First set the value (for example "dark") and restart the app:
DBAdapterdb=newDBAdapter(this);
try {
db.open();
db.UpdateOption("theme", "dark");
}
catch (Exception ex) {}
finally {
db.close();
}
finish();
Intentintent=newIntent(this, ActionBarTabsPager.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Then you get the new value and set the THEME
DBAdapterdb=newDBAdapter(this);
Cursorc=null;
try {
db.open();
c = db.GetOption(c, "theme");
Stringtheme= c.getString(1);
if (theme.equalsIgnoreCase("dark")) {
THEME = R.style.Theme_Sherlock;
}
elseif (theme.equalsIgnoreCase("light")) {
THEME = R.style.Theme_Sherlock_Light;
}
elseif (theme.equalsIgnoreCase("darklight")) {
THEME = R.style.Theme_Sherlock_Light_DarkActionBar;
}
}
catch (Exception ex) {}
finally {
try {
if (c != null)
{
c.close();
c = null;
}
}
catch (Exception ex){}
db.close();
}
setTheme(THEME);
I have a tabel OPTIONS to save some settings. This can also be done with shared preferences of course.
Post a Comment for "Actionbarsherlock Restart To Apply Theme Triggers Wrong Lifecycle Methods"