2

I have an AsyncTask called from Activity1 and Activity2 that is visible now. From Activity2 I am making some changes in the running AsyncTask and AsyncTask must requery cursor in my Activity2.

How do I verify that Activity2 is visible and requery cursor within it from AsyncTask?

Mat Nadrofsky
  • 8,289
  • 8
  • 49
  • 73
Sviatoslav
  • 1,301
  • 2
  • 17
  • 42

1 Answers1

0

I am a little confused -> you want to requery a cursor, that is not in your AsyncTask, but in your Activity? Don't you use AsyncTasks, exactly, to do DB Queries in separate Thread? So why would you like to do that? On the subject of how to (try to) detect if your activity is visible, there's already an answer

EDIT:

You should have defined the AsyncTask as private class to an Activity (I assume you did it like that for Activity1). All methods in AsyncTask, except doInBackground() are executed on the UI Thread of the Activity you've defined the task in. You don't have to call directly onProgressUpdate(), instead you have to use publishProgress(), but I think you cannot call it from your Activity2.

I am not sure what exactly you're trying to achieve, but maybe you should consider looking at Handlers.

Community
  • 1
  • 1
hovanessyan
  • 30,580
  • 6
  • 55
  • 83
  • 1
    My **AsyncTask** loading all info in the DB. During this I can open **Activity2** and tell my **AsyncTask** to load info for **Activity2** at first. **AsyncTask** make it and must call the **method** (_in onProgressUpdate_) in my **Activity2** (_this method will recreate/requery cursor in Activity2_). – Sviatoslav Nov 17 '11 at 19:01
  • +1 for the interesting use case. Generally, the entire life cycle of an AsyncTask is bound to a particular activity (private inner class). consider use a separate AsyncTask in Activity2 for requery cursor. – yorkw Nov 17 '11 at 20:16