Android App Development and Web Server Interactions

后端 未结 4 1656
轻奢々
轻奢々 2021-01-01 07:45

I am just learning about Android Development so excuse me if this is a bit off in nature. I am wanting to make an app that interacts with a Database from my website, in a se

4条回答
  •  误落风尘
    2021-01-01 08:12

    The approach you mention in the question: PHP on the server and JSON for requests/responses, does work. But getting it perfect can be tricky.

    I found it helpful to have small request/reponse classes for each call on the Android side, like SaveNoteToServerRequest, SaveNoteToServerResponse classes which are just plain java objects with whatever fields are needed for the request/response. Then you can use a library like GSON to convert the request object to JSON and convert the http response from JSON to the response object.

    On the PHP side you can create a small class for the response object, then json_encode at the end.

    That way you're not directly manipulating JSON objects, just using your own plain java objects or php classes most of the time.

    Hope that helps.

提交回复
热议问题