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

Using asynctask for network connection

I am trying to incorporate asynctask into my code as I get a force close at the minute due to NetworkOnMainThreadException. I have gone through a few tutorials but I still cannot get my head around it. Every time I try it out, I just get errors all…
3
votes
3 answers

Using AsyncTask for android network connection

I am having some trouble using AsyncTask as I have never come across it before and have no clue what I am doing with it. Basically I am getting a force close because I am trying to run the connection on a main class. Could someone possibly help me…
3
votes
1 answer

ProgressBar not spinning during data source operations in background task

I am trying to load some data into a layout. I am loading the data via an AsyncTask, which will load data from an SQLite datasource then insert that data into the layout on completion. I'd like to show a progress bar during this time, by adding it…
John Q Citizen
  • 321
  • 1
  • 6
  • 15
3
votes
4 answers

how to put progress bar in starting of a new activity

i Have two activities A and B. i used intent to jump from A to B. now in B. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_main); LoadData(); } now in…
3
votes
4 answers

Android progress not working accordingly

I'm new to Android and Java. I have been working on my task i.e, Image Downloader. Where I have to download images with progress bar and display them in grid. I have created two classes 1. URLImageAdapter 2. CacheActivity. Everything works fine but…
3
votes
1 answer

One AsyncTask for multiple Activities

I'm writting an app that uses WebServices to retrieve data. Initially I had a private AsyncTask class for each activity that needed data from the WebService. But I've decided to make the code simpler by creating AsyncTask as a public class. All…
Alejandro Alcalde
  • 5,990
  • 6
  • 39
  • 79
3
votes
3 answers

How to avoid the ANR dialog Application Not Responding

I'm working on an Android app, which uses an online service, which I need to load my Fragments. Basically, I have a menu, and each button replaces a Fragment underneath. When I click a button, the fragment starts being replaced, and if I press…
ximena
  • 33
  • 1
  • 1
  • 4
3
votes
1 answer

Android ksoap2 Throws Exception with AsyncTask

I've a function that connects to a web service and returns the SoapObject. This function works without a problem if I call it directly without the AsyncTask but the following code throws an exception. Any suggestions? private class LoginTask…
3
votes
1 answer

Progress Dialog is shown only for a very little time in Async Task and the activity loading is slow

I'm developing my first Android application and i want to show a progress dialog until a xml file is being processed in doInBackground method. This activity is loaded in response to an onclick event. Unexpectedly, activity takes several seconds to…
3
votes
0 answers

Custom AsyncTaskLoader class doesn't honor calls to forceLoad

This is a bit of a weird problem. I'm using a class that extends AsyncTaskLoader (real deal targeting API level 11, not the compatibility one) to receive intents sent by another app component and respond by downloading some data from a local…
3
votes
2 answers

Worker thread from AsyncTask blocks UI thread

I'm making an android application which downloads JSON file in the AsyncTask class after SEARCH BUTTON in Activity is clicked. And I want to display Progress Dialog on the Activity while downloading data. But on my AVD and device, actual action is…
KAKY
  • 61
  • 1
  • 6
3
votes
1 answer

Stop an HttpURLConnection connecting

This question was asked and answered some time ago link. However the answer did not help me yet. I am in sort of the same position as the OP of the other post: I have an Asynctask in which I make a connection to a certain website, however, most of…
3
votes
2 answers

How to stop ASyncTask from crashing when my activity changes or destroys?

This MAY be a duplicate of another question, I am not sure. I've read similar questions, but either wasn't able to make sense of it, or wasn't able to successfully apply the given solutions. I've created an application that has multiple tabs. Most…
Vic V
  • 1,080
  • 2
  • 12
  • 31
3
votes
3 answers

I'm using AsyncTask and getting threading errors

I'm making a request to the Yelp API through an AsyncTask innerclass. When I try to print the result in onPostExecute() i get errors. Heres my code: public class MainActivity extends Activity { Yelp yelp = new yelp(....); yelp.execute(); public…
A H
  • 235
  • 2
  • 5
  • 15
3
votes
2 answers

Android - setAdapter() in AsyncTask

I need to fill the ListView with AsyncTask. This code works, the TextView changes to "Begin", then "End". But the ListView is blank, not showing. In the log I see "array = 3". package a.test3; import java.util.ArrayList; import…