diff options
author | Oddbjørn Bakke <oddbjorn.bakke@gmail.com> | 2016-08-17 11:26:27 +0200 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2016-08-17 10:26:27 +0100 |
commit | cb2bcdb84c45dad15cf470b798069f2ab301bf19 (patch) | |
tree | 66eab2f8e0ab7ff46b4b1d6cce04c7f12411f4a9 | |
parent | e488f7f3189d5bafecf36f79c4fb1862d662350b (diff) | |
download | xamarin-forms-cb2bcdb84c45dad15cf470b798069f2ab301bf19.tar.gz xamarin-forms-cb2bcdb84c45dad15cf470b798069f2ab301bf19.tar.bz2 xamarin-forms-cb2bcdb84c45dad15cf470b798069f2ab301bf19.zip |
[Android] Fix for NullReferenceException when using the wrong activit… (#286)beta-2.3.2-pre2
* [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
-rw-r--r-- | Xamarin.Forms.Platform.Android/KeyboardManager.cs | 6 |
1 files changed, 6 insertions, 0 deletions
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) |