Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Can't request location updates via pending intent from non-ui thread #131

Closed
amayatsky opened this issue Oct 21, 2016 · 5 comments
Closed

Comments

@amayatsky
Copy link

amayatsky commented Oct 21, 2016

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)

@ecgreb
Copy link
Collaborator

ecgreb commented Oct 21, 2016

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?

@ecgreb ecgreb added the bug label Oct 21, 2016
@ecgreb ecgreb removed the bug label Nov 29, 2016
@ecgreb
Copy link
Collaborator

ecgreb commented Nov 29, 2016

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 ecgreb closed this as completed Nov 29, 2016
@amayatsky
Copy link
Author

amayatsky commented Nov 30, 2016

@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.

@ecgreb
Copy link
Collaborator

ecgreb commented Nov 30, 2016

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.

@ecgreb ecgreb reopened this Nov 30, 2016
@ecgreb ecgreb self-assigned this Nov 30, 2016
@ecgreb ecgreb removed their assignment Nov 30, 2016
@ecgreb ecgreb added ready and removed in progress labels Dec 1, 2016
@sarahsnow1 sarahsnow1 self-assigned this Dec 6, 2016
@ecgreb ecgreb added next and removed in progress labels Jan 18, 2017
@sarahsnow1 sarahsnow1 removed their assignment Mar 13, 2017
@sarahsnow1 sarahsnow1 added ready and removed next labels May 10, 2017
@msmollin msmollin removed the ready label May 17, 2017
@sarahsnow1
Copy link
Contributor

@amayatsky this has been resolved in the 2.3.0-SNAPSHOT. Please upgrade to that version or wait for an official release. Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants