I'm using a LocationListener to obtain locations. The locations must continue being registered even when my app has no visible activities/fragments (such as user pressing Home button).
What is the difference in these designs:
1) Registering the LocationListener in an activity. Unregister it in onDestroy.
2) Registering the LocationListener in a service. User must stop this service from an activity.
Will my listener be called even if the activity is not visible?
What thread will actually call my listener? My app main thread or a system thread?
If it is called in both (1) and (2), what are the pros and cons?
Better design proposals are very welcome.
[Edit 1 start]
I've found the answer for my question about which thread will call the listener. Depending on the overload of requestLocationUpdates used, it will either be the supplied Looper thread or the calling thread (which must be a Looper thread).
Source: 1
"If a LocationListener is used but with no Looper specified then the calling thread must already be a Looper thread such as the main thread of the calling Activity. If a Looper is specified with a LocationListener then callbacks are made on the supplied Looper thread."
This basically means, if I want to offload the main thread, I need to either supply a Looper thread to requestLocationUpdates or create a worker thread when the listener is called. And I still don't see the difference in doing this from a service or from an activity.
[Edit 1 end]