From b04b5a1a1e21f9e30d548cef9b11b01093869896 Mon Sep 17 00:00:00 2001 From: Kevin Petit Date: Wed, 29 Jan 2020 12:55:49 +0100 Subject: [PATCH] [Android] Refresh main page on activity resume if main page has been changed when activity was paused (#9257) fixes #9093 fixes #5236 --- .../AppCompat/FormsAppCompatActivity.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs index 334fbb6d4..92dd31c26 100644 --- a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs +++ b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs @@ -55,6 +55,7 @@ namespace Xamarin.Forms.Platform.Android bool _renderersAdded; bool _activityCreated; + bool _needMainPageAssign; bool _powerSaveReceiverRegistered; PowerSaveModeBroadcastReceiver _powerSaveModeBroadcastReceiver; @@ -341,6 +342,13 @@ namespace Xamarin.Forms.Platform.Android _previousState = _currentState; _currentState = AndroidApplicationLifecycleState.OnResume; + if (_needMainPageAssign) + { + _needMainPageAssign = false; + + SetMainPage(); + } + if (!_powerSaveReceiverRegistered && Forms.IsLollipopOrNewer) { // Start listening for power save mode changes @@ -397,6 +405,12 @@ namespace Xamarin.Forms.Platform.Android // Activity in pause must not react to application changes if (_currentState >= AndroidApplicationLifecycleState.OnPause) { + // If the main page is set after the activity has been paused, delay it to resume step + if (args.PropertyName == nameof(_application.MainPage)) + { + _needMainPageAssign = true; + } + return; }