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
3
votes
1 answer

Filter ListView in real time

I want to filter a ListView in real time. I have an EditText in the ActionBar, and each time the user writes a character I want to update the cursor of the ListView filtering the information. I have done an AsyncTask to perform the query but I have…
michael_ferl
  • 275
  • 1
  • 3
  • 8
3
votes
2 answers

Can I determine if an activity has running AsyncTasks?

During many of my tests, my app is running AsyncTasks that access the database and cannot be cancelled. At the end of my tests, I close my database, delete it, then reopen it so I have a fresh database fixture. The problem is that when the…
Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
3
votes
2 answers

android: cancel(true) does not kill the AsyncTask

I am using an Android AsyncTask in order to download files from a server. when files are downloaded, I am trying to kill the AsyncTask. protected void onPostExecute(Void result) { MyTask.cancel(true); } But it stills running (I can see it from…
user1471575
  • 731
  • 2
  • 15
  • 23
3
votes
0 answers

ProgressDialog updating in onProgressUpdate, recounting when big size file downloading in Android

I'm writing program to download large size of file (~ 280 MB) from a remote server. Downloading process working perfectly although it takes lot of time. Then I used a ProgressDialog to show the current state of the downloading process. It is also…
AnujAroshA
  • 4,623
  • 8
  • 56
  • 99
3
votes
0 answers

Android BaseExpandableListAdapter with AsyncTask saving list state

I've been trying to figure this out for days now, after searching and searching and searching I gave up and decided to ask the community. Any help is greatly appreciated. I am extending BaseExpandableListAdapter and using the Lazy Image Loading…
3
votes
2 answers

read of Inputstream non stop when internet connection lost

I'a using a asynctask to download file. It works normally until i turn off wifi connection (there are no other internet connection) of my android, download dialog still and no changes. When i check by log, i discover that function read() of…
Kiradev
  • 347
  • 2
  • 17
3
votes
3 answers

How can I ensure an AsyncTask is completed before my activity is killed?

I'm getting an Unable to destroy activity xxx: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements error while my activity is being destroyed. I presume this is because I'm performing database operations from…
Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
3
votes
3 answers

Image change when i scroll gridview

GridView load images from URL. When i scrolls gridview, more image chance, how to do fix it... I have tried imageAdapter.notifyDataSetChanged(), gridView.invalidateViews().. I have not found a solution to this problem. public class ImageAdapter…
bulubuloa
  • 597
  • 1
  • 10
  • 21
3
votes
1 answer

Threading in Android to process long running processes

Ok, here is my problem. I want to learn AsyncTask, Threading and Handler to process long running tasks. I used Android Cook Book and New Boston Android tutorial, but I can't make it work. I need to change the progress bar message. This is not for…
Isuru Madusanka
  • 1,397
  • 4
  • 19
  • 27
3
votes
0 answers

Fixing SoundManager.release ANR from trace.txt

I am getting the following ANRs while calling SoundPool.release(). This is not a consistent defect, but happening randomly. Hence reproducing it is kinda time consuming. There are 2 ways to fix it, AsyncTask or Thread. I don't think I can use a…
Siddharth
  • 9,349
  • 16
  • 86
  • 148
3
votes
0 answers

Adding views dynamically in AsyncTask

I am creating some text and image views in a loop, with some data received from another class, how can i create those text and image views and use the addview method in a AsyncTask ? I am using addview in the doInBackground method, which doesn't…
Jason Costa
  • 73
  • 2
  • 12
3
votes
2 answers

AsyncTask OnPostExecute not updating TextView

I have an AsyncTask running. I have a TextView that I mimic the message a Toast initially produces. I want to clear the TextView upon success in OnPostExecute but it not doing so. The task complete Toast works fine. How do I set the TextView in the…
user1445716
  • 442
  • 6
  • 18
3
votes
1 answer

Use AsyncTask to Load Bitmap Images

I am trying to load an image in the background as someone works through my app. The logic I wrote is this: public class ImageLoader extends AsyncTask { private String URL; private int type; ImageLoader(String…
Nathan Tornquist
  • 6,468
  • 10
  • 47
  • 72
3
votes
3 answers

Why AsyncTask behaves differently if declared as inner class of an Activity or on a separate file?

I'm using an ORM for Android called Sugar to persist my models on the database and I'm using it inside my AsyncTask. Here is its declaration: public class LoginTask extends AsyncTask { private Context context; …
kaneda
  • 5,981
  • 8
  • 48
  • 73
3
votes
3 answers

If I start an AsyncTask during onCreate, when will it begin execution?

I want to ensure that I don't slow down my app's startup time and need to start a background task that's unrelated to user input--for instance, filling a cache. If I start an AsyncTask from my onCreate method, when will the doInBackground method…
Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246