I want to make an app for android that updates via the internet so the information is always current. What is the best way to implement this?
I want to make an app for android that updates via the internet so the information in the app is always current. What is the best way to implement this?
I understand I will need the information stored somewhere? And I will need to be able to access it and read it into the app?
I am not looking for specific code so much as a general way this could be implemented. As an example think of a weather app t开发者_开发百科hat must pull weather data from an online source.
Thanks
In general you could achieve what you want in one of the following ways (both are popular methods and used in many apps):
- Implement a web service layer to pull the data from the server back to your application. In Android, this is normally done via JSON based REST API. JSON is used nowadays as the data is regarded more compact that XML and it's easier to deal and manipulate in Android.
- Note that it's common to implement caching in phone local storage if the data is not updated frequently.
- Most of the time, the authoritative data is stored in the server
- With this method, you could arrange the layout freely on your app. However, you need to write Java code to arrange the layout
- You could also add better interactivity especially if you are thinking that your UI will have a lot of touch interfaces or animation
- Other way you could do this is by developing a mobile HTML webpage that you could embed in Android via Webview. A simple tutorial is available on Android's website
- This method will retrieve HTML from the server, the same way your desktop browser retrieves HTML. The only difference is that the HTML is mobile optimized. Good example of mobile optimized HTML is gMail from Google
- Using this method, unless you have full control of the server side, you don't necessary can control the layout as the server is the one that generates the HTML
- A lot of times that interactivity is reduced with this approach though Javascript framework such as Sencha and others are quickly reducing the interactivity gap between native code (#1) and using HTML
精彩评论