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

Multiple downloads using asynctask

For my app (supporting Android 2.2+) I have to check HTML-code of a lot (approx 700) of different web-pages and retrieve a single name from each web-page. I have all the URL's stored in an array. I now use a single Asynctask and iterate over the…
XorJoep
  • 65
  • 7
3
votes
2 answers

AsyncTask - what parameters are needed for extending and doInBackground?

What is wrong with this code that uses AsyncTask? In particular: - what parameters do I need to put in fetchSchools - what parameters do I need to put in doInBackground? I've found lots of "helpful" examples but they all use pseudocode in these…
rihallix
  • 356
  • 1
  • 8
  • 22
3
votes
1 answer

Save the fragment state in tabs switch

it is one week I try to solve this problem whitout success. Please help me. I use the tabs navigation with viewpager. This is the class where I put the tabs and the FragmentPagerAdapter class: public class Detail extends SherlockFragmentActivity…
3
votes
2 answers

Is there something similar to onPreExecute and onPostExecute for traditional Threads?

I was using AsyncTask and just switched over to using a traditional Thread for reasons not worth going into for the sake of this question. What can I do to make something execute before and after the thread starts, similar to the functionality of…
Kalina
  • 5,504
  • 16
  • 64
  • 101
3
votes
4 answers

How to create asyncTask to prevent networkOnMainThreadException

I'm new to android application development. I tried to develop an android server client chat for my first project. This is the code for the client side. When the client press btnJoin, it will connect to the server and send a string. I've read many…
Hanny Udayana
  • 388
  • 3
  • 21
3
votes
1 answer

NetworkOnMainThreadException while using AsyncTask

I am making an app that uses the internet to retrieve information. I get an NetworkOnMainThreadException as I tried to run it on 3.0 and above and have therefore tried to set it up using AsyncTask, but it still gives the exception and I don't know…
STHOH
  • 261
  • 1
  • 12
3
votes
1 answer

AsyncTask exception

I'm beginner in Android development, I'm working at my fisrt app and I met a problem. I have to download some images throw internet, and show them in activity. I have a UI delay until the images are downloaded, so I must use multithreading. I read…
3
votes
3 answers

Android AsyncTask On Exit Exception

I'm having problems with my Asynctask. Whenever I exit my app with my BACK button, it just caught an exception. Please take a look at my codes. Please help me to correct it. Thanks. AndroidFragment.java public class AndroidFragment extends…
KC Chai
  • 1,607
  • 9
  • 30
  • 59
3
votes
3 answers

How can I interrupt Callables in an AsyncTask when the AsyncTask.cancel() method is invoked?

My Activity has an AsyncTask whose doInBackground method you can see below. I have to make multiple search request to multiple servers and in order to speed up the execution I've used Java's ExecutorService to make concurrent requests. This works…
Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382
3
votes
3 answers

Why does not AsyncTask automatically update GraphView after append new data?

My main Thread extends from Activity, it starts two asynchronous tasks that gather data from different UDP sources. One of this tasks should append the data to this graph drawing library. I am making updates on the UI from the onPostExecute section…
Hauke S.
  • 43
  • 5
3
votes
4 answers

How to add progress bar to standalone Asynctask?

I have an asynctask that is in its own activity. I pass it a string value and it connects to my web service and downloads Json data based on the name I pass in, returning the Json resultset. Works great. I'd like to add a progress spinner to the…
3
votes
2 answers

AsyncTask for longer than a few seconds?

The API reference states, AsyncTasks should ideally be used for short operations (a few seconds at the most.) Is the problem with a doInBackground that takes, say, 30 seconds that the thread pool might run out of threads? And if that's the…
arbee
  • 45
  • 1
  • 5
3
votes
2 answers

How to finish Activity from AsyncTask Android

In my Application I have 3 Activities: 1. Login 2. AsyncTask (different class) 3. Welcome After receiving all the information in the Login Activity it moves to the AsyncTask Activity. When the the AsyncTask is completed it moves to the Welcome…
Abhishek Dhiman
  • 1,631
  • 6
  • 25
  • 38
3
votes
3 answers

Android Download Image From URL and show in Imageview

I want to show my downloaded image in my Imageview. I'm getting error " Type mismatch: cannot convert from ImageView to Bitmap " . Its saying I cannot show Bitmap images in imageview. Can anyone show me a way to accomplish it? public class…
Android Novice
  • 536
  • 3
  • 14
  • 33
3
votes
2 answers

Want to create a generic AsyncTask - how?

In my Apps I usually have lots of AsyncTasks. They all look the same thus share the same design. So I would like to optimize this a little bit further and create a generic MyAsyncTask from which my AsyncTasks extend. But I don't know how to do…
Harald Wilhelm
  • 6,656
  • 11
  • 67
  • 85