I had the same problem and solved it this way.
@Override public void onCreate(Bundle savedInstanceState) { if (getIntent().hasExtra("bundle") && savedInstanceState==null){ savedInstanceState = getIntent().getExtras().getBundle("bundle"); } //add code for theme switch(theme) { case LIGHT: setTheme(R.style.LightTheme); break; case BLACK: setTheme(R.style.BlackTheme); break; default: } super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //code }
this code is designed to recreate a downturn and change the theme. You must write your own onSaveInstanceState (Bundle outState); From API-11 you can use recreate () method instead
Bundle temp_bundle = new Bundle(); onSaveInstanceState(temp_bundle); Intent intent = new Intent(this, MainActivity.class); intent.putExtra("bundle", temp_bundle); startActivity(intent); finish();
source share