简体   繁体   中英

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

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.

您不能,因为这些操作需要时间,并且您也不想在等待它们的同时阻止UI。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM