title: Android: How to I apply a theme to all the activities of application after selecting one from preferences?
body: <p>I have made a simple app and i want to change the theme of all the activities of the app (including the settings activity) after selecting  from the preference but the themes do not apply after selection. I've tried adding a recreate() but gets stuck in trying to start the main activity. For now, i added a menu item that does recreate() but i want it to apply automatically once you leave the settings activity.</p>
  
  <p>MainActivity.java:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
  
      SharedPreferences getData = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
      String themeValues = getData.getString("theme_preference", "1");
  
      if (themeValues.equals("1")) {
          setTheme(R.style.Theme_Light);
      }
  
      if (themeValues.equals("2")) {
          setTheme(R.style.Theme_Dark);
      }
  
      if (themeValues.equals("3")) {
          setTheme(R.style.Theme_Red);
      }
  
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.activity_main);
  }
  
  @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
  @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          if (id == R.id.action_settings) {
              Intent i = new Intent("com.cyanoise.helloworld.SettingsActivity");
              startActivity(i);
  
          return true;
      }
  
      if (id == R.id.about_app) {
          startActivity(new Intent(MainActivity.this, AboutActivity.class));
  
          return true;
      }
  
      if (id == R.id.refresh_app) {
          recreate();
  
          return true;
      }
  
      if (id == R.id.exitapp) {
          finish();
      }
  
      return super.onOptionsItemSelected(item);
  }
  </code></pre>
  
  <p>SettingsActivity.java:</p>
  
  <pre><code>public class SettingsActivity extends PreferenceActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          addPreferencesFromResource(R.xml.settings);
      }
  }
  </code></pre>
  
  <p>All answers are greatly appreciated.</p>