Crash when open notification when app is in foregroud
bigpjo opened this issue ยท 1 comments
๐ Bug Report
A notification is received whilst the app is in the background, if you bring the app to the foreground and then open the notification from the notification bar the app crashes with a
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.
[mono-rt] at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.59(intptr,intptr)
[mono-rt] at (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.59(intptr,intptr)
The OnNotificationOpened seems to fire correctly through.
Expected behavior
OnNotificationOpened event should process as normal
Reproduction steps
Send a notification whilst the app is in the background
Bring app to foreground
Click the notification from the system notification
App crashes
Configuration
Version: 3.4.25
Xamarin.Forms: 5.0.0.2401
Platform:
- ๐ค Android
- ๐ Xamarin.Forms
A bit more information. I have found this is being caused by the splash screen.
When the notification is clicked whilst the app is in the foreground, a new splash activity is created, which OnResume
protected override void OnResume() { base.OnResume(); Intent intent = new Intent(this, typeof(MainActivity)); if (Intent.Extras != null) { intent.PutExtras(Intent.Extras); } intent.AddFlags(ActivityFlags.NoAnimation); StartActivity(intent); OverridePendingTransition(0, 0); Finish(); }
This fires
protected override void OnNewIntent(Intent intent) { base.OnNewIntent(intent); FirebasePushNotificationManager.ProcessIntent(this, intent); }
of the MainActivity, this then causes the exception