I am making a network call in AsyncTask, but the problem I am facing is the amount of time it takes to run the doInBackground method.
Here is part of my code:
button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.d("Temp:",System.currentTimeMillis()+""); new Move().execute();
And my AsyncTask:
private class Move extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... temp) { Log.d("start:",System.currentTimeMillis()+""); gson.fromJson(Web.Request.get(some_URL),Void.class); Log.d("end:",System.currentTimeMillis()+""); return null; } }
These are the logs I received:
32658-998/com.example.game D/temp:﹕ 1408923006159 32658-998/com.example.game D/start:﹕ 1408923035163 32658-998/com.example.game D/end:﹕ 1408923035199
Thus, it took almost 29 seconds to reach the first line in the doInBackground method, since it took only 36 ms to complete the network call. I tried this many times, the time spent is almost in the same order.
Can I run AsyncTask right away? Or is there another way to solve this problem (other than running a simple thread?) Thanks :)
source share