Connect Android application to remote data

2019-05-21 19:00发布

问题:

Sheesh talk about limited information! I'm trying to get my Android application to connect to an online database to access information. There's quite a bit of info including geotags and these are going to be mapped on my app. The developer site has the very informative piece of information:

You can use the network (when it's available) to store and retrieve data on your own web-based services. To do network operations, use classes in the following packages:

java.net.*
android.net.*

Like I said in my previous question, I'm still very much an android newbie, and trying to remember my java oop from college is slow. Does anyone have an example of how this might work, or how I could implement it? I wouldn't mind even connecting to a local xml file, if I could find a good example of how to do that!? Am I just looking in all the wrong places?!

Help. Please!

T

回答1:

You can use SAXParser to parse XML from the net. Here's a tutorial on how to use the same.



回答2:

How do you plan to connect to the database?

Android allows you do to plain socket communication which you can refresh your knowledge of here:

http://java.sun.com/developer/onlineTraining/Programming/BasicJava2/socket.html

Another method would be to put up a REST type service and respond with XML. SAX is commonly used for XML parsing in Android:

http://www.saxproject.org/