summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.ControlGallery.Android
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2017-09-21 17:42:43 (GMT)
committerJason Smith <jason.smith@xamarin.com>2017-09-28 21:59:12 (GMT)
commit8ff07402ecdd3ebc8bde30942be48e4c95ed4a01 (patch)
tree3224d7a0b68607e0cd45e260f7381f279d9da9c2 /Xamarin.Forms.ControlGallery.Android
parent4382364030f2b54ab1a72f1b36aee98801cdc257 (diff)
downloadxamarin-forms-8ff07402ecdd3ebc8bde30942be48e4c95ed4a01.zip
xamarin-forms-8ff07402ecdd3ebc8bde30942be48e4c95ed4a01.tar.gz
xamarin-forms-8ff07402ecdd3ebc8bde30942be48e4c95ed4a01.tar.bz2
Prevent Flags/IsInitialized check from crashing Android app on restart (#1151)
* Prevent Android app crashes on configuration restarts when flags are set * Update UI test * Fix typos * Don't prevent FastRenderers flag from being set
Diffstat (limited to 'Xamarin.Forms.ControlGallery.Android')
-rw-r--r--Xamarin.Forms.ControlGallery.Android/Activity1.cs25
-rw-r--r--Xamarin.Forms.ControlGallery.Android/FormsAppCompatActivity.cs4
-rw-r--r--Xamarin.Forms.ControlGallery.Android/FormsApplicationActivity.cs5
3 files changed, 34 insertions, 0 deletions
diff --git a/Xamarin.Forms.ControlGallery.Android/Activity1.cs b/Xamarin.Forms.ControlGallery.Android/Activity1.cs
index eb32a4b..9036cc5 100644
--- a/Xamarin.Forms.ControlGallery.Android/Activity1.cs
+++ b/Xamarin.Forms.ControlGallery.Android/Activity1.cs
@@ -13,6 +13,7 @@ using Xamarin.Forms.Controls.Issues;
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms.Platform.Android.AppLinks;
using Android.Content;
+using Android.Content.Res;
using Android.Views;
using AColor = Android.Graphics.Color;
@@ -146,6 +147,30 @@ namespace Xamarin.Forms.ControlGallery.Android
{
_app.Reset();
}
+
+ void SetUpForceRestartTest()
+ {
+ // Listen for messages from the app restart test
+ MessagingCenter.Subscribe<RestartAppTest>(this, RestartAppTest.ForceRestart, (e) =>
+ {
+ // We can force a restart by making a configuration change; in this case, we'll enter
+ // Car Mode. (The easy way to do this is to change the orientation, but ControlGallery
+ // handles orientation changes so they don't cause a restart.)
+
+ var uiModeManager = UiModeManager.FromContext(this);
+
+ if (uiModeManager.CurrentModeType == UiMode.TypeCar)
+ {
+ // If for some reason we're already in car mode, disable it
+ uiModeManager.DisableCarMode(DisableCarModeFlags.None);
+ }
+
+ uiModeManager.EnableCarMode(EnableCarModeFlags.None);
+
+ // And put things back to normal so we can keep running tests
+ uiModeManager.DisableCarMode(DisableCarModeFlags.None);
+ });
+ }
}
}
diff --git a/Xamarin.Forms.ControlGallery.Android/FormsAppCompatActivity.cs b/Xamarin.Forms.ControlGallery.Android/FormsAppCompatActivity.cs
index 9a33107..2ad6369 100644
--- a/Xamarin.Forms.ControlGallery.Android/FormsAppCompatActivity.cs
+++ b/Xamarin.Forms.ControlGallery.Android/FormsAppCompatActivity.cs
@@ -45,6 +45,8 @@ namespace Xamarin.Forms.ControlGallery.Android
#if TEST_EXPERIMENTAL_RENDERERS
Forms.SetFlags("FastRenderers_Experimental");
+#else
+ Forms.SetFlags("Fake_Flag"); // So we can test for flag initialization issues
#endif
Forms.Init(this, bundle);
@@ -71,6 +73,8 @@ namespace Xamarin.Forms.ControlGallery.Android
// Listen for the message from the status bar color toggle test
MessagingCenter.Subscribe<AndroidStatusBarColor>(this, AndroidStatusBarColor.Message, color => SetStatusBarColor(global::Android.Graphics.Color.Red));
+ SetUpForceRestartTest();
+
LoadApplication(_app);
}
diff --git a/Xamarin.Forms.ControlGallery.Android/FormsApplicationActivity.cs b/Xamarin.Forms.ControlGallery.Android/FormsApplicationActivity.cs
index 15f40d2..a4e1bba 100644
--- a/Xamarin.Forms.ControlGallery.Android/FormsApplicationActivity.cs
+++ b/Xamarin.Forms.ControlGallery.Android/FormsApplicationActivity.cs
@@ -6,6 +6,7 @@ using Android.Content.PM;
using Android.OS;
using Java.Interop;
using Xamarin.Forms.Controls;
+using Xamarin.Forms.Controls.Issues;
using Xamarin.Forms.Platform.Android;
namespace Xamarin.Forms.ControlGallery.Android
@@ -23,6 +24,8 @@ namespace Xamarin.Forms.ControlGallery.Android
if (!Debugger.IsAttached)
Insights.Initialize(App.InsightsApiKey, ApplicationContext);
+ Forms.SetFlags("Fake_Flag"); // So we can test for flag initialization issues
+
Forms.Init(this, bundle);
FormsMaps.Init(this, bundle);
Forms.ViewInitialized += (sender, e) => {
@@ -43,6 +46,8 @@ namespace Xamarin.Forms.ControlGallery.Android
// When the native binding gallery loads up, it'll let us know so we can set up the native bindings
MessagingCenter.Subscribe<NativeBindingGalleryPage>(this, NativeBindingGalleryPage.ReadyForNativeBindingsMessage, AddNativeBindings);
+ SetUpForceRestartTest();
+
LoadApplication(app);
}