Arci
Arci

Reputation: 6819

Activity's UI freezes on AsyncTask's onPostExecute?

I used AsyncTask to request for a large chunk of data. When received, the data is processed inside the onPostExecute method. It may take a while to process the data.

Based from my understanding, AsyncTask is asynchronous and is independent from the UI.

Upvotes: 0

Views: 1479

Answers (4)

Gani
Gani

Reputation: 58

  1. You should do all your datasource operations like(database , network ,parsing the response.etc) in doInBackground method.
  2. If you want update any ui updation in async task the use onProgressUpdate
  3. I think you are performing any parsing operations in onPostExecute. try getting filtered or parsed data (lighter data) in onPostExecute.

Upvotes: 2

Vibhuti Sharma
Vibhuti Sharma

Reputation: 93

Make sure you are using doInBackground method in your AsynTask method.

Upvotes: 0

Ankitkumar Makwana
Ankitkumar Makwana

Reputation: 3485

see Long Running Task You Need to Bind in doInBackground here you cannot Bind UI control Like Button, ImageView etc. After completion of doInBackground in onPostExecute you can Bind All Require Control, make sure here[onPostExecute] you not runnning Another task.

Upvotes: 0

Nickolai Astashonok
Nickolai Astashonok

Reputation: 2888

Why does my Activity freezes onPostExecute?

According your post, you perform some time consuming operation on PostExecute method. On PostExecute is running on UI thread, so it's okay that you UI is freezed.

Is it normal for an Activity to freeze if processing inside the onPostExecute method is too long?

Yes, it's. You should perform long operation in doInBackground method (non-UI thread)

How do I make it such that my Activity won't freeze onPostExecute?

Try to transfer your long time operation to doInBackground method and in PostExecute just update UI according response, which you get after operations in doInBackground method.

Upvotes: 1

Related Questions