title: Open same fragment after activity recreate
body: <p>I have fragment container activity in which I replace fragments as per operations. In one fragment I am providing options to change primary color for app. So user can change toolbar and other components tint color. 
  but after applying theme i recreate activity so my toolbar in base activity also reinitialized with new color code. </p>
  
  <p>Now my problem is my app sequence is like this 
  <strong>Setting > User settings > Theme Settings</strong></p>
  
  <p>so when user change theme i want to display same fragment again after recreate. 
  I have seen other questions also and applied logic also but not working for me.</p>
  
  <p><strong>Code to change theme</strong></p>
  
  <pre><code>private void setThemePreference(String primary, String primaryDark, String text) {
      int requiredLength = 0;
  
      if (primary.length() &lt; 6) {
          requiredLength = 6 - primary.length();
  
          for (int i = 0; i &lt; requiredLength; i++) {
  
              primary = "0" + primary;
          }
      }
  
      if (primaryDark.length() &lt; 6) {
          requiredLength = 6 - primaryDark.length();
  
          for (int i = 0; i &lt; requiredLength; i++) {
  
              primaryDark = "0" + primaryDark;
          }
      }
  
      if (text.length() &lt; 6) {
          requiredLength = 6 - text.length();
  
          for (int i = 0; i &lt; requiredLength; i++) {
  
              text = "0" + text;
          }
      }
  
      UserPreferenceManager.preferencePutString(
          AppConstants.SharedPreferenceKeys.PrimaryColor,primary);
      UserPreferenceManager.preferencePutString(
          AppConstants.SharedPreferenceKeys.PrimaryDarkColor, primaryDark);
      UserPreferenceManager.preferencePutString(
          AppConstants.SharedPreferenceKeys.PrimaryTextColor, text);
      UserPreferenceManager.preferencePutBoolean(
          AppConstants.SharedPreferenceKeys.IS_ThemeChanged, true);
  
      TaskStackBuilder.create(getActivity())
          .addNextIntent(new Intent(getActivity(), MainActivity.class))
          .addNextIntent(getActivity().getIntent())
          .startActivities();
  
      // applied this also
      //getActivity().recreate();
  
      getActivity().overridePendingTransition(0, 0);
  }
  </code></pre>
  
  <p>Code to open theme fragment</p>
  
  <pre><code>getActivity().getSupportFragmentManager()
      .beginTransaction()
      .setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left)
      .addToBackStack(TAG)
      .replace(R.id.container, fragment)
      .commit();
  </code></pre>
  
  <p>Please guys help. I have not much experience and not even fresh new developer.</p>