Description
I have already asked this question before #74 . Previously I forked this library and added lifecycle listener inside the module and turned location updates on/off when react-native activity changes state.
You could ask me why implement inside the native module when you can directly listen for AppState
inside JS and start and stop tracking. Reason: I wanted showLocationDialog
to be true, as you know the showLocationDialog shows an activity over our activity hence, if I listen to AppState
then I will get state events for this enable settings dialog also but I cannot know if this event is fired due to this dialog. If I stop tracking when this Dialog opens thinking my app has gone to background then user presses OK
in this Dialog, 1. The native portion calls getLocationUpdates
which will setup a callBack for fusedLocationProvider and 2. Since the Dialog closed after pressing OK
, foreground event is fired from AppState
which in turn will call start tracking again. Hence the first getLocationUpdates
call and its callback can never be accessed in native side and the location update keeps running.
To solve this problem I hacked a solution on native side which starts and stops tracking location handling this edge case. Now I thought how to fix it in the library by default
Now Android 10 and onwards (Targeting) by default supports whenInUse and Always similar to iOS. What is the best to handle these cases in devices less than Android 10.
- Do you have a straightforward idea to handle it in library?
or - What is the best way to handle it in our code base instead of in library?
BTW, thanks for the library