Questions tagged [android-asynctask]

Use for questions on android.os.AsyncTask

AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.

AsyncTask is designed to be a helper class around Thread and Handler and does not constitute a generic threading framework. AsyncTasks should ideally be used for short operations (a few seconds at the most).

WARNING : The AsyncTask has an implicit reference to the enclosing Activity. If a configuration change happens the Activity instance that started the AsyncTask would be destroyed, but not GCd until the AsyncTask finishes. Since Activities are heavy this could lead to memory issues if several AsyncTasks are started. Another issue is that the result of the AsyncTask could be lost, if it's intended to act on the state of the Activity. Replace the AsyncTask by the new AsyncTaskLoader

More information:

14544 questions
47
votes
1 answer

Android AsyncTask example and explanation

I want to use an AsyncTask in my app, but I am having trouble finding a code snippet with a simple explanation of how things work. I just want something to help me get back up to speed quickly without having to wade through the documentation or lots…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
46
votes
4 answers

Can't Override onPostExecute() method in AsyncTask Class or get it to trigger

I am having trouble getting the onPostExecute() method to call when running an AsyncTask. When I try to set up my class extending AsyncTask in which the onPostExecute() is overridden I get the following build error. 'The method onPostExecute() of…
Ben
  • 515
  • 1
  • 6
  • 9
46
votes
2 answers

AsyncTask Threading Rule - Can it really only be used once?

In the documentation on AsyncTask it gives the following as a rule related to threading: The task can be executed only once (an exception will be thrown if a second execution is attempted.) All this means is that you have to create a new…
stormin986
  • 7,672
  • 15
  • 42
  • 54
45
votes
4 answers

How to use AsyncTask correctly in Android

I don't want to pass any arguments to doInBackground method of the AsyncTask. So what should be the code like?
omerjerk
  • 4,090
  • 5
  • 40
  • 57
43
votes
2 answers

Android: AsyncTask recommendations: private class or public class?

I'm currently developing some Android Apps in a team and we've used 2 different approaches during the last months (one that i personally prefere, and the other that the other developer prefers). Although so far the results are the same, this got me…
neteinstein
  • 17,529
  • 11
  • 93
  • 123
43
votes
2 answers

Invalid heap address and fatal signal 11

Every so often my app will crash and my log will read: @@@ ABORTING: INVALID HEAP ADDRESS IN dlfree Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1) Sometimes code=2, but always Fatal signal 11 and invalid heap address. I've tried researching what…
adneal
  • 30,484
  • 10
  • 122
  • 151
41
votes
4 answers

Android wait AsyncTask to finish

I have a function, AppHelper.isOnline(Context context), I call in various parts of my application to check that a session didn't timeout before making an HTTP request. public void onClick(View v) { Intent intent = null; switch…
max4ever
  • 11,909
  • 13
  • 77
  • 115
41
votes
5 answers

How to handle AsyncTask onPostExecute when paused to avoid IllegalStateException

I appreciate the numerous postings regarding AsyncTask on a rotation change. I have the following problem when using the compatability lib and trying to dismiss a DialogFragment in onPostExecute. I have a fragment which fires of an AsyncTask which…
PJL
  • 18,735
  • 17
  • 71
  • 68
40
votes
11 answers

AsyncTask onPostExecute never gets called

I am not sure what I am doing wrong but onPostExecute never gets called. Created a base class called BaseActivity.java From my original Activity I extended this class. Placed PostToOpenFeint class inside BaseActivity Called it from the UI thread…
ddavtian
  • 1,361
  • 3
  • 14
  • 16
40
votes
3 answers

Common class for AsyncTask in Android?

I have a common class say for eg Class A which extends AsyncTask and has all the methods implemented i.e. onPreExecute, doinbackground and onPostExecute. Now, there are other classes which want to use Class A object. Say Class B uses class A in the…
sunil
  • 9,541
  • 18
  • 66
  • 88
40
votes
2 answers

What is the most efficient way on Android to call HTTP Web API calls that return a JSON response?

I'm the perfectionist type, I already got web API calls working fine with Google Places API (just as an example), but I feel it's sometimes slow or maybe I'm not doing it right. Some blogs are saying I should use AndroidHttpClient, but I'm not,…
Mohamed Heiba
  • 1,813
  • 4
  • 38
  • 67
40
votes
7 answers

Android: How to update an UI from AsyncTask if AsyncTask is in a separate class?

I hate inner class. I've a main activity who launches a 'short-life' AsyncTask. AsyncTask is in a separate file, is not an inner class of main activity I need async task updates a textView from main Activity. I know i can update a TextView from…
realtebo
  • 23,922
  • 37
  • 112
  • 189
39
votes
5 answers

What is the use of List or ArrayList

I want to know about What is the use of List or ArrayList in android? Specially when we are using web services using AsyncTask<...>
Zubair Ahmed
  • 2,857
  • 2
  • 27
  • 47
38
votes
5 answers

Passing arguments to AsyncTask, and returning results

I have an application that does some long calculations, and I would like to show a progress dialog while this is done. So far I have found that I could do this with threads/handlers, but didn't work, and then I found out about the AsyncTask. In my…
Bojan Ilievski
  • 1,272
  • 2
  • 14
  • 22
38
votes
8 answers

onPostExecute not called after completion AsyncTask

For some reason my onPostExecute() is not called after my AsyncTask finishes. My class decleration: public class setWallpaperForeground extends AsyncTask My onPostExecute(): protected void onPostExecute(Boolean…
mlevit
  • 2,676
  • 10
  • 42
  • 50