There is an example of how to start searching and sending coordinates every five minutes using an alarm clock, but if you close the application with the back
key, sending will stop pretty quickly, because an error will occur in the class LocationTracker.java
because:
Location currentLocation = LocationProvider.getInstance().getCurrentLocation();
Will give null
.
I think this happens because in SinglePhone LocationProvider.java
Context
is lost after the application is closed. After the error, the singleton tries to work with another Context
, but the interaction does not work because the Context
is different.
I'm right?
How to save the Context
in SharedPreferences
to get it and substitute it into a singleton when the application with the context is closed?
sleep()
for 5 minutes to your thread? - anber