Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit cb2bcdb

Browse files
oddbearrmarinho
authored andcommitted
[Android] Fix for NullReferenceException when using the wrong activit… (#286)
* [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
1 parent e488f7f commit cb2bcdb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Xamarin.Forms.Platform.Android/KeyboardManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ internal static class KeyboardManager
1111
{
1212
internal static void HideKeyboard(this AView inputView, bool overrideValidation = false)
1313
{
14+
if (Forms.Context == null)
15+
throw new InvalidOperationException("Call Forms.Init() before HideKeyboard");
16+
1417
using (var inputMethodManager = (InputMethodManager)Forms.Context.GetSystemService(Context.InputMethodService))
1518
{
1619
IBinder windowToken = null;
@@ -26,6 +29,9 @@ internal static void HideKeyboard(this AView inputView, bool overrideValidation
2629

2730
internal static void ShowKeyboard(this AView inputView)
2831
{
32+
if (Forms.Context == null)
33+
throw new InvalidOperationException("Call Forms.Init() before ShowKeyboard");
34+
2935
using (var inputMethodManager = (InputMethodManager)Forms.Context.GetSystemService(Context.InputMethodService))
3036
{
3137
if (inputView is EditText || inputView is TextView || inputView is SearchView)

0 commit comments

Comments
 (0)