I am developing an app for android mobiles that communicates with a json/rest web service. I need to make certain kinds of calls periodically to the server to check for some information. Within that context I might need also to query the GPS for the current position. I'm quite undecided to use a Local Service, since I don't know very well how to deal with them, in fact I need to retrieve those data periodically and refresh a MapView accordingly. I heard that I can use PendingIntents,in the service, associate this data as a payload and send them to a broadcast receiver which unpack the data and refresh the UI, I heard also that this is a bad design approach because of what broadcast receiver are intended to be used for. does anybody have some useful hints?
相关问题
- 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
- Design RESTful service with multiple ids
- Listening to outgoing sms not working android
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Using JAX-WS 2.2.5 client with JDK/JRE 1.5
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
first you have to deal with google maps since you will display a mapview. Have a look at this Using Google Maps in Android on mobiForge.
Second you need a class that provides gps data. It is simple to get location data and update UI using message handler. Here is an example:
In your onCreate method make an instance of this class and the locationlistener will start to listen for gps updates. But you can not access lng and lat since you do not know from your activity wheather they are set or null. So you need a handler that sends a message to your main activity when lat and lng are set:
Modify in the following method:
In your main activity add this:
Since the handler is in your mapactivity you can update your UI easily in the handler itself. Everytime gps data is aviable a message is triggered and received by the handler.
Developing a REST API is a very interesting thing. A easy way is to have a php script on a webserver that on request returns some json data. If you want to develope such a service this tutorial might help you, link.