开发者

Android Communicate with a Location Manager started from another activity

开发者 https://www.devze.com 2023-01-12 05:45 出处:网络
In my app I want to obtain a gps lock and record the coords. But I do not want to lock the device into looking for the gps. The user is to be free to traverse through the app and the different activit

In my app I want to obtain a gps lock and record the coords. But I do not want to lock the device into looking for the gps. The user is to be free to traverse through the app and the different activities within.

So If I call a locationListener in activity A, can I reference it in activities B C and D?

if is was still in activity A I could say something like

A.this.mlocListe开发者_如何学Cner.removeMyUpdates();

When I am in activity B how can I reference the LocationListener I set up in Activity A

Thanks in advance

Kevin


No. Set up a broadcast when you have a location event you want the other activities to see. Or user a service to do the locationlistener and then you can bind to it. Keep in mind that you should unregister locationlisteners in your onPause() method if you're using it in an activity. It will drain the user's battery

0

精彩评论

暂无评论...
验证码 换一张
取 消