Bug 32733 - Switching Activity crash in
Summary: Switching Activity crash in
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.4.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-08-03 22:15 UTC by Stephen Moyer
Modified: 2016-09-20 12:56 UTC (History)
10 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Stephen Moyer 2015-08-03 22:15:22 UTC
After updating the Xamarin.Forms package in NuGet to, the app was crashing trying to start the main activity from the SplashActivity.

The specific error is: 

08-03 20:43:27.783 I/MonoDroid(24963): System.NullReferenceException: Object reference not set to an instance of an object
08-03 20:43:27.783 I/MonoDroid(24963): at Xamarin.Forms.Platform.Android.KeyboardManager.HideKeyboard (Android.Views.View,bool) <IL 0x0000a, 0x00078>
08-03 20:43:27.783 I/MonoDroid(24963): at Xamarin.Forms.Platform.Android.FormsApplicationActivity.OnPause () <IL 0x00007, 0x0004b>
08-03 20:43:27.783 I/MonoDroid(24963): at Android.App.Activity.n_OnPause (intptr,intptr) [0x00009] in /Users/builder/data/lanes/1978/2e8568c9/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.App.Activity.cs:3896
08-03 20:43:27.783 I/MonoDroid(24963): at (wrapper dynamic-method) object.50f86df8-524d-4d70-bf00-89b30e5aa8a9 (intptr,intptr) <IL 0x00011, 0x0003b>

Reverting to fixed the issue.
Comment 1 Kristopher Nguyen 2015-08-23 21:58:19 UTC
I have exact the same issue.
Comment 2 Niels 2015-08-24 06:04:00 UTC
Same issue here.
Comment 3 Paul DiPietro [MSFT] 2015-09-06 21:13:15 UTC
Could you please provide a reproduction project? It would be much appreciated.
Comment 4 Peter Hagane 2016-04-11 11:26:35 UTC
Got the same problem. Reproduction project: https://github.com/patsy02/KompetansetorgetXamarin

I can deploy just fine on emulator (visual studio android emulator), but deployment on a physical device produces these same errors.

My Xamarin.Forms nuget is currently on
Comment 5 Rui Marinho 2016-04-13 18:44:07 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Forms. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.
For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d

Warm regards,
Xamarin Forms Team
Comment 6 Willem Mali 2016-06-09 09:25:07 UTC
I am still encountering this bug when creating an AppCompat splashscreen. I can't set the issue to active.
Comment 7 oddbjorn.bakke 2016-07-06 09:20:28 UTC
I think NOT_REPRODUCIBLE is the wrong status for this bug, and this is also a easy one. However the bug itself is a little wrong. By the description from Stephen Moyer, this should be easily reproducible.

This is a typical problem if you inherit the splashscreen from FormsActivity instead of Activity. Since the Context is not set in Forms.Context.

The real bug is then:
Xamarin Should probably give a better exception, and that is what this bug is really all about. Xamarin Forms 2.3 still gives a generic null reference exception.


Proof of bug:

Ex. Exception happens when calling OnPause:

Then this will call:

However, the Forms.Context is null in situation of a splashscreen.

In the splashscreen case, use baseclass:
Activity, AppCompatActivity

Instead of baseclass:
FormsAppCompatActivity, FormsApplicationActivity

To see what happens in the Forms.Init, se SetupInit in:

Where: Context = activity;


Possible fix:
public static Context Context { get; internal set; }

static Context _context;
public static Context Context
    if(_context == null)
      throw new InvalidOperationException("FormsApplication not Initialized, run Forms.Init first.");
    return _context;
  internal set { _context = value; }
Comment 8 Rui Marinho 2016-08-17 09:35:20 UTC
Should be fixed in 2.3.3-pre1
Comment 9 Parmendra Kumar 2016-09-20 12:56:24 UTC
I have checked this issue with 2.3.3-pre2 and this issue no longer reproducible with latest Xamarin forms version 2.3.3-pre2.

Hence closing this issue.

If you still facing same issue, Please feel free to reproduce this issue.