Jacob,

A static member variable, possibly wrapped in a singleton is how you can get the thread. Otherwise, your activity isn't going to know that the thread already exists on second (and subsequent) launches. The thread would set the static to null when it's about to exit.

However, using a simple background thread isn't a very good match for an Android application. You should consider running your worker thread in a service, probably IntentService.

-- Kostya

23.03.2011 23:23, Jacob пишет:
Hi

I have a Activity class, a Thread class. The activity object creates
the thread object and starts the thread. I can communicate with the
thread via Handler class. The thread is running and doing some simple
data fetching thru web.

Question/Issue.

If I press the back button on the Activity dialog, activity is gone;
the thread is still running and I like it that way. When I restart the
activity (by clicking on the app icon), how do I restore the
communication with the running thread?
I am not comfortable with the 2 solutions I know: 1) I don't want the
thread class be a singleton. 2) static member variable in activity to
hold the thread object.

Is there any other cleaner way to do this? I would like the thread
object be gone once I am done with this thread; making it singleton,
static, I don't know when it gets destroyed.

Any suggestion is appreciated.

Thank you
Jacob



--
Kostya Vasilyev -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to