-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
When I clean the application data (including cache) and run CrossGeofence.Current.StartMonitoring. The plugin crash and the exception is:
Message: System.NullReferenceException: 'Object reference not set to an instance of an object.'
StackTrace:
at Plugin.Geofence.GeofenceImplementation.RequestMonitoringStart () [0x00000] in <793ebe419a94494388f459127f8240ff>:0
at Plugin.Geofence.GeofenceImplementation.StartMonitoring (Plugin.Geofence.GeofenceCircularRegion region) [0x00061] in <793ebe419a94494388f459127f8240ff>:0
When I read the GeofencePlugin code, I think it's because mGoogleApiClient isn't initialized.
Andorid Service:
using Android.App;
[Service]
public class GeofenceService : Service
{
public override void OnCreate()
{
base.OnCreate();
System.Diagnostics.Debug.WriteLine("Geofence Service - Created");
}
public override StartCommandResult OnStartCommand(Android.Content.Intent intent, StartCommandFlags flags, int startId)
{
System.Diagnostics.Debug.WriteLine("Geofence Service - Started");
return StartCommandResult.Sticky;
}
public override Android.OS.IBinder OnBind(Android.Content.Intent intent)
{
System.Diagnostics.Debug.WriteLine("Geofence Service - Binded");
return null;
}
public override void OnDestroy()
{
System.Diagnostics.Debug.WriteLine("Geofence Service - Destroyed");
base.OnDestroy();
}
}
In MainApplication
public class MainApplication : Application, Application.IActivityLifecycleCallbacks
{
public static Context AppContext;
public MainApplication(IntPtr javaReference, JniHandleOwnership transer)
:base(javaReference, transer)
{
}
public override void OnCreate()
{
base.OnCreate();
AppContext = this.ApplicationContext;
RegisterActivityLifecycleCallbacks(this);
//TODO: Initialize CrossPushNotification Plugin
//TODO: Replace string parameter with your Android SENDER ID
//TODO: Specify the listener class implementing IPushNotificationListener interface in the Initialize generic
//CrossPushNotification.Initialize<CrossPushNotificationListener>("<ANDROID SENDER ID>");
CrossGeofence.Initialize<CrossGeofenceListener>();
CrossGeofence.RequestLocationPermission = true;
//Start a sticky service to keep receiving geofence events when app is closed.
StartService();
}
public static void StartService()
{
AppContext.StartService(new Intent(AppContext, typeof(GeofenceService)));
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, typeof(GeofenceService)), 0);
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(Context.AlarmService);
alarm.Cancel(pintent);
}
}
public static void StopService()
{
AppContext.StopService(new Intent(AppContext, typeof(GeofenceService)));
if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
{
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, typeof(GeofenceService)), 0);
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(Context.AlarmService);
alarm.Cancel(pintent);
}
}
Metadata
Metadata
Assignees
Labels
No labels