Im currently doing some network related stuff,
public void postData() {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.xx.xx.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
in an asynctask, which i am executing from a service.
What i would like to know is if its enough to run the network methods directly in the service? Because AFAIK it doesnt run on the UI thread.
Thanks
An
IntentServicehas its own thread and you don’t need theAsyncTaskbut a normalServiceruns on the UI thread and you need to move the operations that take a long time to another thread(like using theAsyncTask). TheServicerunning on the main UI thread is stated in the docs.