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

android sqlite query returns cursor with 0 results

I do call an AsyncTask passing a method to be executed, to be certain a method that returns a row named NAME from a specific id. upon calling database query/raw query on doInBackground it returns a cursor with null results even tried with query…
Theofilos Mouratidis
  • 1,146
  • 12
  • 32
3
votes
2 answers

AsyncTask has errors - beginner

Eventually I am wanting this method to look up some values in a text document and return true of the username and password are present there. However I am having some problems with implementing the AsyncTask. I have tried to follow the guide at…
Michael Murphy
  • 1,921
  • 2
  • 18
  • 21
3
votes
3 answers

Android - How to work with AsyncTasks in Class

I'm building an app which communicates with an API. I put all the API communication code and data handling in one API class so that every time I want to use the API I have a central spot where all the logic lies. The thing is that for HTTPRequests…
Ron
  • 22,128
  • 31
  • 108
  • 206
3
votes
1 answer

How to refresh activity after creating dynamic controls in android

In my activity Oncreate() function im calling an AsyncTask. In that PostExecute() im creating some dynamic gallery controls and calling ImageAdapterL.notifyDataSetChanged();. but Im getting Null Pointer exception. I need to refresh the activity…
Vignesh
  • 2,295
  • 7
  • 33
  • 41
3
votes
3 answers

How to kill a AsyncTack thread properly in Android?

I subclass an AsyncTask in my Android project. I want to implement a feature that allow user to cancel the current AsyncTack and start a new one if the current task take too much time. MyAsyncTask mat = new MyAsyncTask(); When the user click the…
Dragon warrior
  • 1,644
  • 2
  • 24
  • 37
3
votes
2 answers

Asynctask < Android 3.0

As I noticed, in Android 3.0 and higher, all AsyncTasks are pushed in the stack and are executed in order, however in earlier versions they are executed independently. Can I somehow apply same style on Android <3.0 as in >=3.0?
Bobans
  • 439
  • 6
  • 13
3
votes
2 answers

Fragement no longer exists for key Error

I have an application with three tabs (TabWidget using fragments). Each tab opens a fragment that contains a a view pager that is based on FragmentStatePagerAdapter. The view pager is populated with items fetched from an online server using Async…
3
votes
1 answer

Use base adapter with asynctask to display listview

i am reading data from soap service and want to display them in a list. to do this, I have created a base adapter. And trying to use that in asynctask. But that is giving some error that i dont have a solution. as per the error i think there is some…
Reza.Hoque
  • 2,690
  • 10
  • 49
  • 78
3
votes
2 answers

One Asynctask for multiple activities?

Basically, I have one Asynctask for downloading files. I can call this from my main UI activity fine, but what if I want to call it from a different Activity - I.e. one activity is a main menu with a link to download the manual, and another activity…
DreamsOfHummus
  • 735
  • 2
  • 7
  • 18
3
votes
1 answer

An error occured while executing doInBackground() Twitter4J

I am using the Twitter4J Library and I am trying to implement some Async Tasks to make some calls to the service as follows. public class TweetsActivity extends Activity { /** Called when the activity is first created. */ @Override public void…
Joel Dean
  • 2,444
  • 5
  • 32
  • 50
3
votes
1 answer

How to use progress dialog in AsyncTask in android

I am developing an app which requires a user to login.The login is working ok through a url. However when i add an AsyncTask to add a progress dialog,the app does not change intent.I have tried every possible method i know in vain. below is the…
mungaih pk
  • 1,809
  • 8
  • 31
  • 57
3
votes
2 answers

Generic asyncTask with callback (for web services)

I've already developed many Android apps that make web service requests, always with the following approach: In every activity that need to make a web service request, I define an inner AsyncTask that shows a ProgressDialog in onPreExecute(), makes…
thelawnmowerman
  • 11,956
  • 2
  • 23
  • 36
3
votes
2 answers

Async Task crashing on backbutton pressed.

What happens to an async task when the calling fragment is paused/removed? I am assuming that the task completes but it would be great of someone can just confirm that. I am trying to find a fix to my crash. I have an async task that is a recursive…
doubleA
  • 2,446
  • 22
  • 45
3
votes
2 answers

getting NetworkOnMainThreadException while integrating twitter API in android

I have searched a lot on it but not able to find a solution. I am trying to integrate twitter in my Android app. It works fine on emulator but does not go well on honeycomb and higher devices. Below, I have attached the log cat error with…
Rohit
  • 490
  • 3
  • 15
3
votes
1 answer

Update fragment of ViewPage with Web Service response

I am new to FragmentActivity, Fragment and ViewPager. I am using FragmentActivity with 2 Fragments. Each fragment is using the same data which I will get from web service call in AsyncTask. Now I don't want to call the Web Service twice for each…
hemu
  • 3,199
  • 3
  • 44
  • 66