As As
As As

Reputation: 2107

Is onLocationChanged thread safe?

Do i need to use a lock or is the android's method onLocationChanged(Location loc) for gps thread safe? I dn't want to have problem, but i don't know if it's already thread-safe because there is nothing in the android documentation about it.

Upvotes: 0

Views: 430

Answers (2)

AlexWien
AlexWien

Reputation: 28727

Since you provide the onLocationChanged() you are responsible if you need thread-saftey. In doubt I would not write to the Location received, if you only read from it, there are no thread-saftey issues with that object.

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006674

onLocationChanged() will be called on whatever thread is associated with the Looper you provided, or the main application thread if you did not provide a Looper.

Whether your code in onLocationChanged() is thread safe depends on what it does and what other threads in your app do.

IOW, method calls are not thread safe; code is thread safe.

Upvotes: 1

Related Questions