How can I apply the Theme without restarting the whole App? If I do it with startActivity(getIntent()); finish();
the Activity quits and dont restart. Is it possible to simply restart / recreate the Activity to apply the theme?
Asked
Active
Viewed 6,898 times
2 Answers
16
It is in the incorrect order.
finish();
intent = new Intent(this, <your_activity>.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
This is the correct order.
Theme can be set before super.onCreate(savedInstanceState);
is being called. You need to destroy the activity and create it again and call immediately setTheme(THEME);
in onCreate()

Dante
- 1,104
- 1
- 10
- 15
-
Do you have a answer on this issue? http://stackoverflow.com/questions/9686912/actionbarsherlock-restart-to-apply-theme-triggers-wrong-lifecycle-methods – Leandros Mar 13 '12 at 16:53
1
Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage( getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

Kamil Budziewski
- 22,699
- 14
- 85
- 105

sandi
- 11
- 1