Creation of AsyncTask taking too much time Android

Posted by user2842342 on Stack Overflow See other posts from Stack Overflow or by user2842342
Published on 2014-08-25T00:49:47Z Indexed on 2014/08/25 4:20 UTC
Read the original article Hit count: 142

Filed under:
|

I am making a network call in an AsyncTask, but the problem i am facing is the amount of time it is taking to start the doInBackground method.

Here is a part of my code:

    button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("Temp:",System.currentTimeMillis()+"");
                new Move().execute();
                /*some other logic
            }
    }

And my AsyncTask is:

    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 got:

           32658-998/com.example.game D/temp:? 1408923006159
           32658-998/com.example.game D/start:? 1408923035163
           32658-998/com.example.game D/end:? 1408923035199

So actually it took almost 29 secs to reach the first line in doInBackground method, where as it took just 36 ms to finish the network call. I tried it many times, the time taken is almost in the same order.

Is it possible to start the AsyncTask immediately? Or is there any other way to solve this problem.(other than a running a simple thread?) Thank you :)

© Stack Overflow or respective owner

Related posts about android

Related posts about android-asynctask