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

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


Attachments

Description Stephen Moyer 2015-08-03 22:15:22 UTC
After updating the Xamarin.Forms package in NuGet to 1.4.4.6392, 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 1.4.3.6376 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 2.1.0.6529
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:
_layout.HideKeyboard(true);
https://github.com/xamarin/Xamarin.Forms/blob/2.3.1/Xamarin.Forms.Platform.Android/FormsApplicationActivity.cs

Then this will call:
Forms.Context.GetSystemService
https://github.com/xamarin/Xamarin.Forms/blob/2.3.1/Xamarin.Forms.Platform.Android/KeyboardManager.cs

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:
https://github.com/xamarin/Xamarin.Forms/blob/2.3.1/Xamarin.Forms.Platform.Android/Forms.cs

Where: Context = activity;

-----------------------------

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

To:
static Context _context;
public static Context Context
{
  get
  {
    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.

Thanks.

Note You need to log in before you can comment on or make changes to this bug.