I need requestLocationUpdates()
to be in a separate Thread, in order to not have it blocking the rest of my application (it will run most of the time). What is the best way to do it?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
When you call
requestLocationUpdates()
this just indicates that you want to be called back when the user's location changes. This call doesn't take a significant amount of time and can be made on the main thread.When the user's location changes (and based on the criteria you pass to
requestLocationUpdates()
) your listener will be called back viaonLocationChanged()
or notified viaIntent
(depending on which parameters you pass torequestLocationUpdates()
). If you do a lot of processing inonLocationChanged()
then you shouldn't run this method on the main thread, but you should just start a background thread (or post aRunnable
to a background thread and do your work on the background thread.Another option is to start a
HandlerThread
and provide theLooper
from theHandlerThread
as a parameter torequestLocationUpdates()
. In that case, the callbacks toonLocationChanged()
will be made on theHandlerThread
. This looks something like this: