domaven / xamarin-plugins

Cross platform Xamarin & Windows plugins for PCLs
MIT License
37 stars 51 forks source link

Plugin is not initialized - When transition triggered while app is not running #29

Open dkarzon opened 7 years ago

dkarzon commented 7 years ago

On Android when running the app and setting up monitoring. If you close the app while still monitoring and trigger one of the transitions (enter, stay, exit, etc.) Android will attempt to call GeofenceTransitionsIntentService but the service will fail with an exception

CrossGeofence - Plugin is not initialized. Should initialize before use with CrossGeofence Initialize method. Example: CrossGeofence.Initialize<CrossGeofenceListener>()

Geofence.Plugin.CrossGeofence.get_Current() in :0
Geofence.Plugin.GeofenceTransitionsIntentService.OnHandleIntent(Android.Content.Intent intent) in :0
Android.App.IntentService.n_OnHandleIntent_Landroid_content_Intent_(System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_intent) in <8d03b60a0cb642ddade14da29ba7cb17>:0
(wrapper dynamic-method) System.Object:106b43ab-ecac-4792-8d4c-15ce6a06ea8d (intptr,intptr,intptr)
ghost commented 6 years ago

On app close you need to specifically remove all the geofences, else android will keep on monitoring the fences and pass on the events to GeofenceTransitionsIntentService.

dkarzon commented 6 years ago

@Shan11812 In this case I want Android to continue to monitor the Geofences after the app is closed. As a work around I have implemented my own GeofenceTransitionsIntentService where I init the service if required and fire off the appropriate code I need to.

Westat-Transportation commented 5 years ago

We addressed this by adding waits to the geofence handlers that only go through after the geofence plugin is initialized, we track initialization in our geofence handling class using a boolean that is set once OnAppInitialized is called.

Westat-Transportation commented 5 years ago

We submitted a couple pull requests that address this and the authors of this package released a new plugin that incorporate them. Try https://www.nuget.org/packages/Plugin.Geofence/, it is almost a complete drop in replacement with the exception of a namespace change and can be used in projects targeting API 27.