Can i do network connections in doInBackground of AsyncTask. If not what to use for this.
As per i know i can use intentService for long running operation but this will lead some complexity in code.
Please suggest for the same.
Can i do network connections in doInBackground of AsyncTask. If not what to use for this.
As per i know i can use intentService for long running operation but this will lead some complexity in code.
Please suggest for the same.
you can run network connections in doInBackground. but using libraries such as volley is better for you. you can learn about volley in :
http://developer.android.com/training/volley/index.html
volley run network connection in background and send result to you in main thread and you don't need to worry about network thread.
Short answer, you can, your network operation will run on the background.
Long answer, I would not recommend using an AsyncTask for that purpose. The main reason:
As other replies have highlighted, depending on your use case you might be able to use Volley.
The short answer is: Yes.
The longer answer is that network communication is always hard, and while the code is definitely simpler when using AsyncTask
compared to other methods, the problems themselves are identical.