Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash | CrossGeofence.Current.StartMonitoring crash in Android after clean application data #31

Open
RumbosN opened this issue Apr 27, 2020 · 4 comments

Comments

@RumbosN
Copy link

RumbosN commented Apr 27, 2020

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);
            }
        }
@bear1770
Copy link

Does anyone have any ideas on this one? I'm getting the same exact error.

@clintonrocksmith
Copy link

clintonrocksmith commented Jul 25, 2020

We also have this issue, just wondering if you're using AndroidX? I'm wondering if the solution needs and upgrade.

For us, it causes an ANR on certain devices.

@clintonrocksmith
Copy link

Hi all,

For anyone who has this, we added the plugin namespace to the linker to exclude it. Then it started working no problems.

My assumption is that the AndroidX migration legacy helper was stripping something out.

Does this work for you?

@clintonrocksmith
Copy link

FYI, we found the crash was fixed when we downgraded to 1.5.4 of the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants