Skip to content Skip to sidebar Skip to footer

Asynctask.get() In Activity.oncreate Makes It Take Too Much Time To Load And Sometimes It Crashes

When I start this activity, it takes too much time to load and sometimes my app crashes. I want to know if there is anything I can do so the activity will no start until the main a

Solution 1:

Your problem is that you're waiting synchronously on the main thread for your AsyncTask to finish:

parsejson.execute().get();

You should basically never be calling AsyncTask.get() on the main thread: it will block the thread until it finishes, which defeats the point of an AsyncTask, which is to not block the main thread.

Instead, you should do whatever you're waiting for in AsyncTask.onPostExecute.

Post a Comment for "Asynctask.get() In Activity.oncreate Makes It Take Too Much Time To Load And Sometimes It Crashes"