开发者

Querying a database from a remote service

I have been working on this little music player for a while and I have been stuck for quite a couple of days in creating a now-playing list. I was thinking abo开发者_运维问答ut storing it inside the database back end. Well, I have a remote interface and what I would like to do is that I would like to query and retrieve data from the database, from that remote interface. Any one would care to shed some lights?


Usually, the best way to do so is creating a REST API in the remote side. As you don't provide too much info let me suppose the remote database lives on a MySQL server and that you have PHP on that remote server too. In that case, you can write a PHP script that reads the database and returns a JSON response containing the data you want. Then, from your android App you just have to query that script and parse what you get.

This has too many advantages:

  • You can easily parse the response using the built-in JSON package (org.json)
  • Let's say you want to create an iPhone version of your app. Then, you just have to reuse the JSON resource you created.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜