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

Starting AsyncTask recursively after a gap of 5 minutes

I want to create an instance of a class (which extends Asynctask) and call its execute() method after every 5 minutes. For that I tried to call Thread.sleep(5*60*1000)) in onPostExecute() method and then create a new instance of the class. The code…
Rajat
  • 1,449
  • 5
  • 20
  • 33
3
votes
1 answer

How to keep the data value and return the data to the main UI, after Asyntask is done?

I'm trying to get the value from AsyncTask class to return to the main UI, even after the AsyncTask class is completed. The string value from onPostExectute() to be saved into json_string for latter use. However, when i tried running this code, it…
thyzz
  • 683
  • 1
  • 9
  • 14
3
votes
1 answer

Android populating spinners from other spinners

I have 3 spinners and a list view. In the first spinner the user selects a state. Then the next spinner down gets populated with all that state's county's. Then the user picks a county and the last spinner gets populated with that county's city's.…
cmb
  • 95
  • 3
  • 12
3
votes
1 answer

Android Service calling AsyncTask

I am having problems when trying to call the constructor of the asynctask inside a service. I got this error Can't create handler inside thread that has not called Looper.prepare(). Should I call the AsyncTask inside a UIThread? Strangely, It is…
3
votes
2 answers

Asynctask and Listener

I have an app that makes numerous RESTful service calls. I execute the calls in a class extending Asynctask. If I have to cancel the asynctask, I also want to cancel the service call. Unfortunately, cancelling the async operation still allows…
eimmer
  • 319
  • 1
  • 3
  • 13
3
votes
1 answer

asynctask not getting arraylist when called from a handler

I'm using a handler to start an asynctask but when doing so, my application crashes. The reason I am stuck is because if I start the asynctask via anything else (eg. onClickListener) then I can run it as many times, over and over again, and it works…
Badams
  • 569
  • 6
  • 25
3
votes
2 answers

Starting asynctask from message handler

I have a gps class in my application. In the onLocationChanged method I am sending a handler message to my activity which is supposed to execute an asynctask. My asyntask runs fine on its own if I call it anywhere from the activity, but I keep…
Badams
  • 569
  • 6
  • 25
3
votes
3 answers

file upload progress jumping to 100% before upload

I am not able to do progress percentage to this file upload function. I googled it a lot i couldn't find solution Here is my code: protected void onProgressUpdate(Integer... progress) { super.onProgressUpdate(progress); …
Noob
  • 2,857
  • 6
  • 33
  • 47
3
votes
3 answers

Android Strict Mode

I have written a simple code on JSON Parsing using AsyncTask. I'm just displaying the response in TextView. I don't know whether it is right or wrong. Its working on GingerBread and showing NetworkOnMainThreadException on JellyBean. If I use…
DroidLearner
  • 2,115
  • 5
  • 31
  • 50
3
votes
2 answers

Android code after httpclient.execute(httpget) doesn't get run in try (using AsyncTask)

I'm trying to get data from a website and parse it into my android application. Unfortunately I don't even get to the part of parsing the data. The code doesn't run after the following line: HttpResponse response = httpclient.execute(httpget); The…
user2192871
  • 33
  • 1
  • 4
3
votes
1 answer

How to Run the Async Task for a set timeout?

I want to run my Async Task which fetches the co-odinates with a certain accuracy and fires up a different activity if it gets co-ordinates. Now I want to setup a time so that if it doesn't gets the co-ordinates with a set accuracy then the Async…
beerBear
  • 969
  • 2
  • 17
  • 41
3
votes
4 answers

How to extract return vlaue of AsyncTask?

I have in my app data retrieval by using http GET method. Once the task finishes, i wish to display the return vlaue in my mainActivity (I have just 1 activity in my app at the moment) This is my asyncTask class: class getAsync extends…
buddy123
  • 5,679
  • 10
  • 47
  • 73
3
votes
2 answers

Calling multiple functions with Asynctask for network connection

II want to build a class that every time I want to do a network connection, I'll use it. I want to open a dialog first and then make the network connection (or get something from SQL or download something from the web or update the SQL) and then…
Raz Cohen
  • 79
  • 1
  • 7
3
votes
5 answers

Android: how to make sure an AsyncTask is terminated before I call another method?

The situation is very simple. I use an AsyncTask to retrieve a String from an HttpClient. Now I need the String retrieved by the AsyncTask to call another method on that String, therefore i need to make sure the AsyncTask has terminated before…
Lisa Anne
  • 4,482
  • 17
  • 83
  • 157
3
votes
1 answer

What is the difference between loading and creating AsyncTask on the UI thread?

While reading AsyncTask documentation, the part on Threading rules, I found this: The AsyncTask class must be loaded on the UI thread. This is done automatically as of JELLY_BEAN. The task instance must be created on the UI…
Amal
  • 971
  • 9
  • 25