fix activity restart upon profile theme change
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 16 May 2020 10:14:13 +0000 (13:14 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 16 May 2020 10:14:13 +0000 (13:14 +0300)
strangely, calling onSaveInstanceState at this time races with
some other thing reacting to the change making fragment manager
crash with "fragment transaction already in progress"

regardless, Actvity.recreate() is designed just for this job

app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java

index 27cc9eb..dace5c4 100644 (file)
@@ -478,21 +478,14 @@ public class MainActivity extends ProfileThemedActivity {
         scheduleDataRetrievalIfStale(newValue);
     }
     private void profileThemeChanged() {
-        Bundle bundle = new Bundle();
-        onSaveInstanceState(bundle);
-
         storeThemeIdInPrefs(profile.getThemeHue());
 
-        // restart activity to reflect theme change
-        finish();
-
         // un-hook all observed LiveData
         Data.profile.removeObservers(this);
         Data.profiles.removeObservers(this);
         Data.lastUpdateDate.removeObservers(this);
-        Intent intent = new Intent(this, this.getClass());
-        intent.putExtra(BUNDLE_SAVED_STATE, bundle);
-        startActivity(intent);
+
+        recreate();
     }
     private void storeThemeIdInPrefs(int themeId) {
         // store the new theme id in the preferences