From cb2bcdb84c45dad15cf470b798069f2ab301bf19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oddbj=C3=B8rn=20Bakke?= Date: Wed, 17 Aug 2016 11:26:27 +0200 Subject: =?UTF-8?q?[Android]=20Fix=20for=20NullReferenceException=20when?= =?UTF-8?q?=20using=20the=20wrong=20activit=E2=80=A6=20(#286)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Android] Fix for NullReferenceException when using the wrong activity type. On using FormsApplicationActivity or FormsAppCompatActivity as base Activity in a SplashScreen. A NullReferenceException will be thrown in the KeyboardManager. Added InvalidOperationException with "Forms.Init()" message instead, if the Forms.Context is null. * Fixed indentation --- Xamarin.Forms.Platform.Android/KeyboardManager.cs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Xamarin.Forms.Platform.Android') diff --git a/Xamarin.Forms.Platform.Android/KeyboardManager.cs b/Xamarin.Forms.Platform.Android/KeyboardManager.cs index db478578..bfe65d13 100644 --- a/Xamarin.Forms.Platform.Android/KeyboardManager.cs +++ b/Xamarin.Forms.Platform.Android/KeyboardManager.cs @@ -11,6 +11,9 @@ namespace Xamarin.Forms.Platform.Android { internal static void HideKeyboard(this AView inputView, bool overrideValidation = false) { + if (Forms.Context == null) + throw new InvalidOperationException("Call Forms.Init() before HideKeyboard"); + using (var inputMethodManager = (InputMethodManager)Forms.Context.GetSystemService(Context.InputMethodService)) { IBinder windowToken = null; @@ -26,6 +29,9 @@ namespace Xamarin.Forms.Platform.Android internal static void ShowKeyboard(this AView inputView) { + if (Forms.Context == null) + throw new InvalidOperationException("Call Forms.Init() before ShowKeyboard"); + using (var inputMethodManager = (InputMethodManager)Forms.Context.GetSystemService(Context.InputMethodService)) { if (inputView is EditText || inputView is TextView || inputView is SearchView) -- cgit v1.2.3