connecting to a webservice from android - AsyncTask or Service?
Posted
by
football
on Stack Overflow
See other posts from Stack Overflow
or by football
Published on 2011-03-07T08:09:17Z
Indexed on
2011/03/07
8:10 UTC
Read the original article
Hit count: 280
I'm writing an android app that will connect to a REST/JSON webservice. Users will be retrieving information, uploading comments, downloading and uploading images etc.
I know that I shouldn't keep all this network communication in the Activity/UI thread, as it will cause ANRs. What I'm confused about is whether I should use an AsyncTask or a Service with "manual" threading to accomplish this;
With a Service, I'd simply have a public method for each method in the webservice's API. I'd then implement threading within each of these methods.
If I used an AsyncTask, I would create a helper class that defined AsyncTasks for each method in the webservice's API.
Which method is preferred? Interaction with the webservice will only happen while the user is in the Activity. Once they switch to another application, or exit the program, there is no need for communication with the webservice.
© Stack Overflow or respective owner