Starting Xamarin foreground service sample crashes

Viewed 115

I'm looking to create a Xamarin foreground service and thought taking the sample from https://github.com/xamarin/monodroid-samples/tree/main/ApplicationFundamentals/ServiceSamples/ForegroundServiceDemo would be a good first step. After building and deploying to my Samsung S10 it just crashes when clicking 'Start Service'.

The line it fails on is TimeStampService.cs line 155, on the code:

var pendingIntent = PendingIntent.GetActivity(this, 0, notificationIntent, PendingIntentFlags.UpdateCurrent); 

With null reference exception. The stack trace:

at Android.Runtime.JNINativeWrapper._unhandled_exception (System.Exception e) [0x0000e] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:12 
at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLII_I (_JniMarshal_PPLII_I callback, System.IntPtr jnienv, System.IntPtr klazz, System.IntPtr p0, System.Int32 p1, System.Int32 p2) [0x00022] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:221 at (wrapper native-to-managed) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLII_I(intptr,intptr,intptr,int,int)

I've tried a few things, including updating to latest versions of references, but still nothing I do fixes this. I tried creating a new background service from scratch and still get the same error.

Does anyone have any ideas how I can fix this?

1 Answers
Related