|
128 | 128 | import org.telegram.messenger.UserNameResolver; |
129 | 129 | import org.telegram.messenger.UserObject; |
130 | 130 | import org.telegram.messenger.Utilities; |
| 131 | +import org.telegram.messenger.LifecycleHelper; |
131 | 132 | import org.telegram.messenger.browser.Browser; |
132 | 133 | import org.telegram.messenger.pip.PipActivityController; |
133 | 134 | import org.telegram.messenger.pip.activity.IPipActivity; |
@@ -965,6 +966,20 @@ public void onPreviewOpenAnimationEnd() { |
965 | 966 | } |
966 | 967 | checkLayout(); |
967 | 968 | checkSystemBarColors(); |
| 969 | + |
| 970 | + // Handle app restoration after process kill |
| 971 | + if (savedInstanceState != null) { |
| 972 | + // Ensure fragments are properly restored |
| 973 | + if (actionBarLayout.getFragmentStack().isEmpty()) { |
| 974 | + if (UserConfig.getInstance(currentAccount).isClientActivated()) { |
| 975 | + DialogsActivity dialogsActivity = new DialogsActivity(null); |
| 976 | + dialogsActivity.setSideMenu(sideMenu); |
| 977 | + actionBarLayout.addFragmentToStack(dialogsActivity); |
| 978 | + drawerLayoutContainer.setAllowOpenDrawer(true, false); |
| 979 | + } |
| 980 | + } |
| 981 | + } |
| 982 | + |
968 | 983 | handleIntent(getIntent(), false, savedInstanceState != null, false, null, true, true); |
969 | 984 | try { |
970 | 985 | String os1 = Build.DISPLAY; |
@@ -6779,6 +6794,11 @@ protected void onPause() { |
6779 | 6794 | pipActivityHandler.onPause(); |
6780 | 6795 | NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.stopAllHeavyOperations, 4096); |
6781 | 6796 | ApplicationLoader.mainInterfacePaused = true; |
| 6797 | + |
| 6798 | + // Ensure UI state is properly saved before going to background |
| 6799 | + if (actionBarLayout != null) { |
| 6800 | + actionBarLayout.saveLastFragment(); |
| 6801 | + } |
6782 | 6802 | int account = currentAccount; |
6783 | 6803 | Utilities.stageQueue.postRunnable(() -> { |
6784 | 6804 | ApplicationLoader.mainInterfacePausedStageQueue = true; |
@@ -6832,6 +6852,21 @@ protected void onStart() { |
6832 | 6852 | if (GroupCallActivity.groupCallInstance != null) { |
6833 | 6853 | GroupCallActivity.groupCallInstance.onResume(); |
6834 | 6854 | } |
| 6855 | + |
| 6856 | + // Ensure fragments are properly restored after app comes back from background |
| 6857 | + if (actionBarLayout != null && actionBarLayout.getFragmentStack().isEmpty()) { |
| 6858 | + // If fragment stack is empty, restore default fragment |
| 6859 | + if (UserConfig.getInstance(currentAccount).isClientActivated()) { |
| 6860 | + DialogsActivity dialogsActivity = new DialogsActivity(null); |
| 6861 | + if (sideMenu != null) { |
| 6862 | + dialogsActivity.setSideMenu(sideMenu); |
| 6863 | + } |
| 6864 | + actionBarLayout.addFragmentToStack(dialogsActivity); |
| 6865 | + if (drawerLayoutContainer != null) { |
| 6866 | + drawerLayoutContainer.setAllowOpenDrawer(true, false); |
| 6867 | + } |
| 6868 | + } |
| 6869 | + } |
6835 | 6870 | } |
6836 | 6871 |
|
6837 | 6872 | @Override |
@@ -6972,6 +7007,27 @@ protected void onResume() { |
6972 | 7007 | onResumeStaticCallback.run(); |
6973 | 7008 | onResumeStaticCallback = null; |
6974 | 7009 | } |
| 7010 | + |
| 7011 | + // Fix for white screen issue after device sleep |
| 7012 | + LifecycleHelper.ensureUIVisible(this, frameLayout, drawerLayoutContainer); |
| 7013 | + |
| 7014 | + // Delayed UI restore if needed |
| 7015 | + if (LifecycleHelper.needsStateRestore(this)) { |
| 7016 | + LifecycleHelper.delayedUIRestore(() -> { |
| 7017 | + if (actionBarLayout != null && actionBarLayout.getFragmentStack().isEmpty()) { |
| 7018 | + if (UserConfig.getInstance(currentAccount).isClientActivated()) { |
| 7019 | + DialogsActivity dialogsActivity = new DialogsActivity(null); |
| 7020 | + if (sideMenu != null) { |
| 7021 | + dialogsActivity.setSideMenu(sideMenu); |
| 7022 | + } |
| 7023 | + actionBarLayout.addFragmentToStack(dialogsActivity); |
| 7024 | + if (drawerLayoutContainer != null) { |
| 7025 | + drawerLayoutContainer.setAllowOpenDrawer(true, false); |
| 7026 | + } |
| 7027 | + } |
| 7028 | + } |
| 7029 | + }); |
| 7030 | + } |
6975 | 7031 | if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_SYSTEM) { |
6976 | 7032 | Theme.checkAutoNightThemeConditions(); |
6977 | 7033 | } |
@@ -8193,6 +8249,12 @@ public void hideVisibleActionMode() { |
8193 | 8249 | protected void onSaveInstanceState(Bundle outState) { |
8194 | 8250 | try { |
8195 | 8251 | super.onSaveInstanceState(outState); |
| 8252 | + |
| 8253 | + // Save current account and app state |
| 8254 | + outState.putInt("currentAccount", currentAccount); |
| 8255 | + outState.putBoolean("isActive", isActive); |
| 8256 | + outState.putBoolean("isResumed", isResumed); |
| 8257 | + outState.putBoolean("isStarted", isStarted); |
8196 | 8258 | BaseFragment lastFragment = null; |
8197 | 8259 | if (AndroidUtilities.isTablet()) { |
8198 | 8260 | if (layersActionBarLayout != null && !layersActionBarLayout.getFragmentStack().isEmpty()) { |
@@ -8236,6 +8298,35 @@ protected void onSaveInstanceState(Bundle outState) { |
8236 | 8298 | FileLog.e(e); |
8237 | 8299 | } |
8238 | 8300 | } |
| 8301 | + |
| 8302 | + @Override |
| 8303 | + protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 8304 | + try { |
| 8305 | + super.onRestoreInstanceState(savedInstanceState); |
| 8306 | + |
| 8307 | + // Restore app state |
| 8308 | + if (savedInstanceState != null) { |
| 8309 | + int savedAccount = savedInstanceState.getInt("currentAccount", currentAccount); |
| 8310 | + if (savedAccount != currentAccount && UserConfig.isValidAccount(savedAccount)) { |
| 8311 | + switchToAccount(savedAccount, false); |
| 8312 | + } |
| 8313 | + |
| 8314 | + isActive = savedInstanceState.getBoolean("isActive", true); |
| 8315 | + isResumed = savedInstanceState.getBoolean("isResumed", false); |
| 8316 | + isStarted = savedInstanceState.getBoolean("isStarted", false); |
| 8317 | + |
| 8318 | + // Ensure UI is visible after restore |
| 8319 | + if (frameLayout != null) { |
| 8320 | + frameLayout.setVisibility(View.VISIBLE); |
| 8321 | + } |
| 8322 | + if (drawerLayoutContainer != null) { |
| 8323 | + drawerLayoutContainer.setVisibility(View.VISIBLE); |
| 8324 | + } |
| 8325 | + } |
| 8326 | + } catch (Exception e) { |
| 8327 | + FileLog.e(e); |
| 8328 | + } |
| 8329 | + } |
8239 | 8330 |
|
8240 | 8331 | @Override |
8241 | 8332 | public void onBackPressed() { |
|
0 commit comments