[android-developers] Re: AsyncTask discrepancy

2010-01-22 Thread Flapjack
Frank, if my AsyncTask is located in my Service, how can I use it to update the UI in my Activity? I'm a bit confused by this- I thought the AsyncTask would have to be located inside the Activity class in order to update the UI within the Activity. On Jan 21, 8:20 pm, Frank Weiss

[android-developers] Re: AsyncTask discrepancy

2010-01-22 Thread Flapjack
Streets of Boston, please forgive my ignorance. If I use AsyncTask within a service to retrieve data once, can I destroy the AsyncTask after? Or would I have to destroy the entire Service? Additionally, if I want to poll, say, every 5 minutes, wouldn't having AsyncTask in the service be a good

[android-developers] Re: AsyncTask discrepancy

2010-01-22 Thread Streets Of Boston
If the AsyncTask finishes executing, the thread on which the asynctask was run just waits (Object.wait()). The AsyncTask is based upon the ExecutorService and FutureTask classes from the java.util.concurrent packages. Creating a new AsyncTask does not create a new thread. An AsyncTask is executed

[android-developers] Re: AsyncTask discrepancy

2010-01-22 Thread Streets Of Boston
If your Service is running in the same process as your Activity, use a static reference to your Activity. E.g. MyActivity.ACTIVE_INSTANCE Be sure to update the ACTIVE_INSTANCE in onCreate (set it to 'this') and onDestroy (set it to 'null'). This will work when you can have only one instance of

Re: [android-developers] Re: AsyncTask discrepancy

2010-01-22 Thread Frank Weiss
That's right. If you start an AsyncTask from a Service, you can't use the UI thread methods of the AsyncTask to access the UI thread. Many of the usages of AsyncTask are from an Activity, not a Service. They are used to respond to user events that would take too long to process in the UI thread,

[android-developers] Re: AsyncTask discrepancy

2010-01-21 Thread Streets Of Boston
A Service, like an Activity, has a main thread with a message-loop. You can create an AsyncTask in the onX() callbacks of Services, just like in an Activity. The onPostExecute can do your handling of the results, as you described. However, AsyncTask is more geared towards the one-time