From be9f626c37949cc56c5f6901dac93093f3016fbf Mon Sep 17 00:00:00 2001 From: "E.Z. Hart" Date: Mon, 18 Jul 2016 17:30:41 -0600 Subject: Prevent FormsAppCompatActivity from loading fragments we don't use on restart (#246) * Prevent FormsAppCompatActivity from loading fragments we don't use on restart * Adding issues lost in merge --- .../AppCompat/FormsAppCompatActivity.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Xamarin.Forms.Platform.Android') diff --git a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs index 6bd7df2b..b6736df2 100644 --- a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs +++ b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs @@ -44,6 +44,9 @@ namespace Xamarin.Forms.Platform.Android int _statusBarHeight = -1; global::Android.Views.View _statusBarUnderlay; + // Override this if you want to handle the default Android behavior of restoring fragments on an application restart + protected virtual bool AllowFragmentRestore => false; + protected FormsAppCompatActivity() { _previousState = AndroidApplicationLifecycleState.Uninitialized; @@ -139,8 +142,17 @@ namespace Xamarin.Forms.Platform.Android callback(resultCode, data); } + protected override void OnCreate(Bundle savedInstanceState) { + if (!AllowFragmentRestore) + { + // Remove the automatically persisted fragment structure; we don't need them + // because we're rebuilding everything from scratch. This saves a bit of memory + // and prevents loading errors from child fragment managers + savedInstanceState?.Remove("android:support:fragments"); + } + base.OnCreate(savedInstanceState); AToolbar bar; -- cgit v1.2.3