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
2 answers

Remove and terminate all tasks from AsyncTask.THREAD_POOL_EXECUTOR

I want to run a number of AsyncTask's on AsyncTask.THREAD_POOL_EXECUTOR. I am using the following code. Tasks[i].executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, taskParams); After…
Evgenii.Balai
  • 939
  • 13
  • 30
3
votes
4 answers

how to make sure that only one AsyncTask runs in the background

I have a class, DownloadAndSave that extends from AsyncTask. In its doInBackground method, it retrieves data from an http connection and saves the data using OrmLite, but also cleans the old entries from the database. So, something like…
user1796624
  • 3,665
  • 7
  • 38
  • 65
3
votes
2 answers

How does AsyncTask SerialExecutor work?

private static class SerialExecutor implements Executor { final ArrayDeque mTasks = new ArrayDeque(); Runnable mActive; public synchronized void execute(final Runnable r) { mTasks.offer(new Runnable() { …
Chen
  • 326
  • 3
  • 12
3
votes
7 answers

out of memory error while using viewpager+imageview even when using cache memory and asynctask

Please did someone add lots of imageviews in a viewpager before? I have an activity that calls the fragment class to create fragments containing images into a viewpager and this fragment class contains methods that caches the image if it doesn't…
3
votes
3 answers

Threads and Asynctask task use for httppost

Friends ,i need help to android httppost data to server using Asynctask or Threads I need to send data to my server when i click post button.But when i click it app need to go to next page and data need to send through as background process.I'm new…
SAGA
  • 349
  • 5
  • 15
3
votes
2 answers

Static call for startActivity from AsyncTask

I have implemented a FragmentPagerAdapter of 4-lashes, and in each of them I load a fragment with a different view. In one of them, pressing an image executed a AsyncTask to obtain a series of data from a server and loads a new class through an…
3
votes
5 answers

Should I use android-async-http client in dobackground of Async task?

Earlier I was using Default Http client of android and then found this library at http://loopj.com/android-async-http/ When I use this library inside doInBackground(String... args) of AsyncTask, I noticed that postExecute() finished before…
3
votes
1 answer

AsyncTask Workflow

I am currently working on an android application that has to handle a network connection using several AsyncTasks. This is the first task that is establishing the connection and calling a new task which is handling the microphone input. private…
Al0x
  • 917
  • 2
  • 13
  • 30
3
votes
1 answer

How to timeout Asynctask and dismiss ProgressDialog?

I've got a problem and hope you can help me. I've got an Asynctask, which starts uploading data if I press a button in my mainactivity. It works fine except if I've got a slow internet connection. The Asynctask starts a progressdialog and if I've…
Har Un
  • 33
  • 1
  • 5
3
votes
4 answers

Retrieving a returned string from AsyncTask in Android

I want to retrieve the contents of this file and save that to a string. I've tried using AsyncTask (based on this answer) and here is my class. class RetreiveURLTask extends AsyncTask { private Exception exception = null; …
stanri
  • 2,922
  • 3
  • 25
  • 43
3
votes
1 answer

Can I pass parameters to preExecute() method in async task?

Id like to manipulate a specific view in an async task before the backround task executes but not sure how I can pass the required parameters to the method. I Just get a null pointer when I do something like this class CalcFib extends…
Brian
  • 4,328
  • 13
  • 58
  • 103
3
votes
2 answers

Progress bar is not shown while AsyncTask is working

I'm trying to implement a progress bar into my application which is shown while my AsyncTask is fetching data. For this I tried to rebuild this SO-Answer ("SO: How to show a progress spinner"). But my progress bar is shown up (and instantly…
bish
  • 3,381
  • 9
  • 48
  • 69
3
votes
0 answers

Android: Most easy and robust way to handle network operations

Mostly we handle network things in AsyncTask(doInBackground method). I have googled many times to find the most easy and robust way to handle network things. I have also searched here to find the appropriate answer. But still I didn't. Maximum…
Ranjit
  • 5,130
  • 3
  • 30
  • 66
3
votes
4 answers

should you create new Async Tasks for every different call or use the same one

So I have an app that will make multipe HTTP Post/Gets E.G. Login, getThisData, getThatData, sendThis, sendThat Is it better to have a seperate AsyncTask to handle each one Or one async task and process them differently with a switch in…
cxzp
  • 652
  • 2
  • 14
  • 28
3
votes
3 answers

Best way to organize AsyncTask

I am a relatively new Android developer and am working on an application right now that makes a lot of calls to a RESTful web service. I am making each call in an asyncTask but in some files, the amount of different async tasks I have approaches 15.…
Marty Griffin
  • 349
  • 1
  • 5
  • 18