You don't need a thread *just* to schedule an event. There is an easier way,
which should also fit your number of activities better.

1 - This needs to be done in the code for each of your activities. Use a
base class, or a delegate object.

2 - In onCreate, make a Handler object with an anonymous inner Callback
(just like for setOnClickListener).

http://developer.android.com/reference/android/os/Handler.html#Handler(android.os.Handler.Callback
)

3 - Define a "what" constant for a special message, which will be used by
this Handler. Doesn't have to be a system-wide unique, in fact a zero will
do.

4 - When you want to schedule a delayed task, do this:

mHandler.sendEmptyMessageAtTime or mHandler.sendEmptyMessageDelayed with the
"what" constant defined above.

http://developer.android.com/reference/android/os/Handler.html#sendMessageAtTime(android.os.Message,
long)

5 - In the handler's callback, check the "what" of the message, and do
whatever needs to be done.

6 - In the activity's onPause or onStop, call this to remove all pending
messages with that "what" value from the event queue:

http://developer.android.com/reference/android/os/Handler.html#removeMessages(int
)

If the operation you're going to perform needs an argument, obtain a message
using this:

http://developer.android.com/reference/android/os/Handler.html#obtainMessage(int,
java.lang.Object)

and post with this:

http://developer.android.com/reference/android/os/Handler.html#sendMessageAtTime(android.os.Message,
long)

or sendMessageDelayed

-- Kostya
2011/6/11 Droid <rod...@gmail.com>

> Thanks for your sensible suggestion. My sentence should have read 'I
> have a timer thread that should not bring an activity back to view
> after the home button has been pressed but it does.'
>

-- 
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

Reply via email to