user1610075
user1610075

Reputation: 1641

Get accelerometer and Location values without listener

I'd like to simply get these values whenever I want and not on events...is it possible? I can't see any method getXValue(), getLatitude(),ecc ...

Upvotes: 0

Views: 734

Answers (2)

bennettaur
bennettaur

Reputation: 1253

These values a generated by hardware, and if there aren't any registered listeners, they don't generate values (to save battery).

For Location, you can call getLastKnownLocation() from the LocationManager but there is no guarantee that you'll get something back or that what you get back will even be relevant.

If you want to just get these values whenever, create listeners and store the values and have methods to return the values. Have your listeners running in a separate thread so you don't lock anything up on the UI.

Also make sure to adjust the frequency at which events are delivered appropriately to avoid doing too much work.

Upvotes: 3

P Varga
P Varga

Reputation: 20219

You can't, because these operations take time, and you wouldn't want to block the UI while waiting for them anyway.

Upvotes: 1

Related Questions