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

How to set the text of a TextView asynchronously?

I have to fill a ListView with text info that takes time to gather. My approach is to use AsyncTask to do the background job, but setting the text to the TextView when the result has arrived slows the list: the list lags every time getView() is…
znat
  • 13,144
  • 17
  • 71
  • 106
3
votes
3 answers

How to show progress dialog when I click on a button using AsyncTask in a class that yet extends MapActivity

I have a program that search some elements and show these on a GoogleMap. I want to show a progress dialog before the end of all procedures that set the various geopoint on the map. Searching I have found this code to show the progress dialog before…
Asgard
  • 388
  • 1
  • 5
  • 16
3
votes
3 answers

Android: Multiple params in Asynctask

I need to pass two params (lv and position) to a Asynctask doInBackground method but I don't know how do it... LoadSound.execute(lv,position) class LoadSound extends AsyncTask<**[ListView,int]**, String, String> thanks! EDIT: I have a listView. If…
user1364684
  • 800
  • 2
  • 8
  • 28
3
votes
3 answers

using remove(int index) function for an XYSeries in aChartEngine

I am writing a code in which the graph must be continiously updated by repeatedly calling the aSyncTask. but to ensure thet the graph doesnot get too compressed, I plan to remove/ delete the oldest entry beyond a point. Presently my code is as…
Rahul
  • 131
  • 1
  • 7
3
votes
3 answers

Android how to implement executing Async task from runnable

The documentation says that execute() must be called from a UI thread. But, since I am updating images every few seconds, I am using a Runnable. And in that, I define the operations that have to be executed. Starting(execute())ASyncTask is one of…
Namratha
  • 16,630
  • 27
  • 90
  • 125
3
votes
1 answer

StrictModeDiskReadViolation only gets resolved with AsyncTask, why?

I am using strict mode for android 3.2 and am getting StrictModeDiskReadViolation during onCreate in my Activity. I tried to moved the code that does an SQL query to: a new Thread. a new AsyncTaskLoader. a new AsynTask. The problem is only…
max4ever
  • 11,909
  • 13
  • 77
  • 115
3
votes
1 answer

nested AsyncTask and onPostExecute

I am using a AsyncTask (1) in another AsyncTask (2). AsyncTask 1 fetches online user data, counts the number of entries in the response and for each entry, in onPostExecute displays a username and runs a new AsyncTask (2) to fetch a image from a…
slinden77
  • 3,378
  • 2
  • 37
  • 35
3
votes
1 answer

Netty framework or how to use it with an AsyncTask

I'm trying to develop an Android application which is going to use Netty. First of all I want to test Netty on Android, so I'm going to develop EchoClient example. I'm "translating" client part. This part has two classes: EchoClient and…
VansFannel
  • 45,055
  • 107
  • 359
  • 626
3
votes
5 answers

AsyncTask detecting if done

I have created an AsyncTask that loads data from a website then when I execute it. At the moment I'm getting a null pointer exception which I think is caused because I'm trying to fill the UI too early so I'm hoping to create some kind of if…
Luke Batley
  • 2,384
  • 10
  • 44
  • 76
3
votes
3 answers

Possible to hide progress text from horizontal style, indeterminate ProgressDialog?

I am showing a horizontal style, indeterminate ProgressDialog as follows: progressDialog.setMessage("My progress dialog…
3
votes
1 answer

Proper way of Fetching request from web service on android

I was just wondering which is the best way to fetch data from a web service using HTTP request. Using AsyncTask or AsyncTaskLoader I'm using AsyncTaskLoader using LoaderManager on the activity but I encounter problems when there are configuration…
3
votes
3 answers

Android AsyncTask and object passing

I need some help on the basic architecture of my code around the login process. I'm implementing Async Http processing to get things working for ICS. the goal of this code is for logging into my app. Login form submit from UI (Login.java) connect…
wired00
  • 13,930
  • 7
  • 70
  • 73
3
votes
1 answer

Android update map location with ASync Task

I have a map view which determines the user location in an ASyncTask and thereafter adds some markers at certain locations on the map. I cannot seem to update the map after a location is found. Is there any possible way to wait for the location to…
kushaldsouza
  • 710
  • 5
  • 12
  • 36
3
votes
1 answer

android.content.Context vs android.app.Activity

I want to pass a reference of the current activity to a method of a class not extending Activity. I need to use this reference to the active activity so that I can use getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON); I pass both the current…
Rynardt
  • 5,547
  • 7
  • 31
  • 43
3
votes
2 answers

Get returned JSON from AsyncTask

So I have this loader class which extends AsyncTask. Then I do new loader().execute(); but I want to use the JSONArray response which my loader class returns how do I do that? Because I need it in several different places? Or should I just move my…
simtaxman
  • 613
  • 2
  • 11
  • 18