From: Damyan Ivanov Date: Sat, 16 May 2020 10:14:13 +0000 (+0300) Subject: fix activity restart upon profile theme change X-Git-Tag: v0.14.0~100 X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=commitdiff_plain;h=eca29dbfd4cae7b051f79ce3cb93f7c55bf092aa fix activity restart upon profile theme change 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 --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index 27cc9eba..dace5c41 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -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