Closed amayatsky closed 7 years ago
Interesting this is exception occurs pretty deep inside the LocationManager
.
Do we know if this use case is supported when calling [LocationManager.requestLocationUpdates(long minTime, float minDistance, Criteria criteria, PendingIntent intent)
](https://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates%28long, float, android.location.Criteria, android.app.PendingIntent%29) directly from a non-UI thread in an application?
It seems this is the expected behavior and is even documented as such in Google Play services.
Closing this issue now but feel free to re-open if you find any deviations between Lost and the Google Play services version.
@ecgreb I think you are looking at the wrong method. I am talking about background updates via Pending Intent. As far as you can see there is no requirement to make a call to this method from a main thread. From my point of view here is what's wrong: your implementation is using a foreground request on a main thread, packs the received locations to intents and sends them?
If that's the case, this quoted part from Google Play Services: "This method is suited for the background use cases, more specifically for receiving location updates, even when the app has been killed by the system" won't work as specified since with the death of the main thread, delivery of locations will stop?
I am asking for this because I am looking for a reliable way for my Background Service to be waken up if killed by delivery of location intent.
Ah yes so I was looking at the wrong method sorry about that. I will take another look at the issue requesting updates from a non-UI thread with a PendingIntent
.
@amayatsky this has been resolved in the 2.3.0-SNAPSHOT
. Please upgrade to that version or wait for an official release. Thank you!
Description
Request location updates via pending intent from a service, from non-ui thread fails.
Steps to Reproduce
Simply request location updates from a non-main thread.
Lost & Android Version
2.1.1, Android 7.0 (24)
Log
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() at android.os.Handler.(Handler.java:200)
at android.os.Handler.(Handler.java:114)
at android.location.LocationManager$ListenerTransport$1.(LocationManager.java:239)
at android.location.LocationManager$ListenerTransport.(LocationManager.java:239)
at android.location.LocationManager.wrapListener(LocationManager.java:871)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:884)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:471)
at com.mapzen.android.lost.internal.FusionEngine.enableNetwork(FusionEngine.java:133)
at com.mapzen.android.lost.internal.FusionEngine.enable(FusionEngine.java:107)
at com.mapzen.android.lost.internal.LocationEngine.setRequest(LocationEngine.java:45)
at com.mapzen.android.lost.internal.FusedLocationProviderServiceImpl.requestLocationUpdates(FusedLocationProviderServiceImpl.java:65)
at com.mapzen.android.lost.internal.FusedLocationProviderService.requestLocationUpdates(FusedLocationProviderService.java:74)
at com.mapzen.android.lost.internal.FusedLocationProviderApiImpl.requestLocationUpdates(FusedLocationProviderApiImpl.java:127)
at *.BackgroundLocationService.requestUpdates(BackgroundLocationService.java:168)