Re: [android-developers] Communicating with the running Thread after Activity is Restarted/Recreated.

2011-03-23 Thread TreKing
On Wed, Mar 23, 2011 at 3:23 PM, Jacob  wrote:

> If I press the back button on the Activity dialog, activity is gone; the
> thread is still running and I like it that way
>

The user will not like it that way. If I close your Activity, I have an
expectation that you will stop what you're doing. If you have a good reason
for continuing a background task, it should be in a Service with an ongoing
notification. This would also solve your problem as then you could bind to
it as necessary to communicate back with your Activity.

-
TreKing  - Chicago
transit tracking app for Android-powered devices

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

Re: [android-developers] Communicating with the running Thread after Activity is Restarted/Recreated.

2011-03-23 Thread Kostya Vasilyev

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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Communicating with the running Thread after Activity is Restarted/Recreated.

2011-03-23 Thread 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

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