I have a lot of crashes on Play Store that I don't know where are coming from or how to reproduce. The stack trace is pointing to ScheduledAlarmHandler. This leads me to believe that the crashes happen when the app is in the background (or killed) and a local notification is fired.
Exception android.runtime.JavaProxyThrowable: System.ArgumentNullException: Value cannot be null. Parameter name: s at System.IO.StringReader..ctor (System.String s) [0x00009] in <2f4adfad501c4e4abfe6a9b300c1b849>:0 at (wrapper remoting-invoke-with-check) System.IO.StringReader..ctor(string) at LocalNotifications.Plugin.ScheduledAlarmHandler.serializeFromString (System.String notificationString) [0x00010] in <42e60f59bb2b4f93942a1c96f54643af>:0 at LocalNotifications.Plugin.ScheduledAlarmHandler.OnReceive (Android.Content.Context context, Android.Content.Intent intent) [0x0000c] in <42e60f59bb2b4f93942a1c96f54643af>:0 at Android.Content.BroadcastReceiver.n_OnReceive_Landroid_content_Context_Landroid_content_Intent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_context, System.IntPtr native_intent) [0x00017] in <1eada6631e384353908e0dab9d072f35>:0 at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLL_V (_JniMarshal_PPLL_V callback, System.IntPtr jnienv, System.IntPtr klazz, System.IntPtr p0, System.IntPtr p1) [0x00005] in <1eada6631e384353908e0dab9d072f35>:0 at crc6449389a0f4059adff.ScheduledAlarmHandler.n_onReceive at crc6449389a0f4059adff.ScheduledAlarmHandler.onReceive (ScheduledAlarmHandler.java:30) at android.app.ActivityThread.handleReceiver (ActivityThread.java:4497) at android.app.ActivityThread.access$1600 (ActivityThread.java:301) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2188) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loop (Looper.java:246) at android.app.ActivityThread.main (ActivityThread.java:8653) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:602) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1130)
I tried wrapping the code in .OnReceive within a PowerManager.WakeLock but it doesn't help.
The exact code to which the stack points is
'''[BroadcastReceiver(Enabled = true, Exported = true)]
[IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted })]
public class ScheduledAlarmHandler : BroadcastReceiver
{
public const string LocalNotificationKeyText = "LocalNotification_TEXT";
public const string LocalNotificationKeyID = "LocalNotification_ID";
public const string LocalNotificationKeyTitle = "LocalNotification_TITLE";
public NotificationManager manager;
public override void OnReceive(Context context, Intent intent)
{
if (context != null)
{
PowerManager pm = (PowerManager)context.GetSystemService(Context.PowerService);
PowerManager.WakeLock wakeLock = pm.NewWakeLock(WakeLockFlags.Partial, "ScheduledAlarmHandler");
wakeLock.Acquire();
var id = intent.GetIntExtra(LocalNotificationKeyID, 0);
var title = intent.GetStringExtra(LocalNotificationKeyTitle);
var text = intent.GetStringExtra(LocalNotificationKeyText);
var notification = new LocalNotification();
notification.Title = title;
notification.Text = text;
notification.Id = id;
manager = getNotificationManager();
var nativeNotification = createNativeNotification(context, notification);
if (notification.Id == 909092)
{
//Remove ongoing notification that you have an active session
manager.Cancel(909093);
}
manager.Notify(notification.Id, nativeNotification);
wakeLock.Release();
}
}
private NotificationManager getNotificationManager()
{
var notificationManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;
return notificationManager;
}'''
Any guidance or help is appreciated.