简体   繁体   中英

How to start a map activity in background and see it when needed in android?

I am making an android app. I have a main activity and i want to show distance and speed on main activity. But there is a button View Map on main activity as well. If user clicks it then he/she should see his/her travelled track on map. User should stop his/run from main activity means that user should be able to go back to main activity and then stop. How can i create map activity which runs in background and show distance and speed in main activity. Thanks in advance.

You should take a look at the Google MyTracks app, it does exactly what you want and it is open source.

http://code.google.com/p/mytracks/

You should probably not think about having an Activity run in the background and instead have some other object that manages all the location information. Most of the time, you only have one Activity on screen and when its not on screen, it is paused and not working.

I would try to have an class that extends LocationListener , manage location information in that object, then whenever it is needed, plug the information into an appropriate View that is shown when the user presses "View Map" button you have.

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