开发者

Is an Android Service a good idea when backing up an app's data using a web service?

开发者 https://www.devze.com 2023-02-16 21:46 出处:网络
I\'d like to add the ability for my android app to save changes to data (stored in it开发者_Go百科s SQLite database) to a web server.The upload will be via HTTP POST, using JSON in the body of the req

I'd like to add the ability for my android app to save changes to data (stored in it开发者_Go百科s SQLite database) to a web server. The upload will be via HTTP POST, using JSON in the body of the request to describe the changes.

I'm wondering if I should use an android Service for this. I'd like the user to be able to continue interacting with the app while it's generating the JSON, making the call to the server, and waiting for the server to complete its work and return a response.

Thanks much!


Even better would be an IntentService

Edit: Now that the compatibility package is out I think the new Loader class may be the best option, possibly using the ASyncTask version or a variation of it.


Yes it is a very good idea to move all the webservice code into a service. The Google IO talk Developing Android REST client applications talks about many reasons why this is a good idea. It also covers other important considerations which relate to your problem which is effectively syncing your database to the cloud.

0

精彩评论

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

关注公众号