]> git.ktnx.net Git - mobile-ledger.git/commitdiff
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 27cc9eba6b68a98e0496130899c8d5cc2a7ae781..dace5c41b19cb854aa5728ff6a5b30a820aba96a 100644 (file)
@@ -478,21 +478,14 @@ public class MainActivity extends ProfileThemedActivity {
         scheduleDataRetrievalIfStale(newValue);
     }
     private void profileThemeChanged() {
         scheduleDataRetrievalIfStale(newValue);
     }
     private void profileThemeChanged() {
-        Bundle bundle = new Bundle();
-        onSaveInstanceState(bundle);
-
         storeThemeIdInPrefs(profile.getThemeHue());
 
         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);
         // 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
     }
     private void storeThemeIdInPrefs(int themeId) {
         // store the new theme id in the preferences