The following should have been the same, if I'm not mistaken.
Using AsyncTask :
private class GetDataTask extends AsyncTask<String, Void, String>{
@Override
protected void onPreExecute() {
}
@Override
protected String doInBackground(String... params) {
return NetConnection.getRecordData(mUserId, mUserPassword);
}
@Override
protected void onPostExecute(String result) {
parseJson(result);
}
}
Usage Subject :
new Thread( new Runnable() {
@Override
public void run() {
String res = NetConnection. getRecordData(mUserId, mUserPassword);
parseJson(res);
}
}).start();
But when the file is downloaded, AsyncTask launches synchronously, and Thread launches asynchronously(in parallel).
Why is that? Why is AsyncTask behaving like this? Is AsyncTask supposed to work asynchronously?
I'm a little confused, so I need your help. This is how I call GetDataTask:
new GetDataTask().execute()
I prefer to use AsyncTask, but this does not work for me. See the earlier question for more information.
source
share