I didn't say anything about a thread - in fact, my recommendation is to not
use a thread just for scheduling stuff (although that Thread.sleep() can
look so tempting...).

As for Handler messages not firing when there aren't any activities on the
screen - that's simply not true.

The event loop continues to run. There may not be any messages to deliver,
but the loop is there ready to do work if needed, just like Binder threads.

I posted a simple test a couple of months ago that showed this.

In fact, that's how component callbacks are delivered, including those to
services and receivers.

-- Kostya
2011/6/12 Indicator Veritatis <mej1...@yahoo.com>

> O...K..., now that we have that clarification, is there anytime that
> the Activity will be paused or stopped (i.e. onPause(), onStop()
> called) when you DO want the timer thread to fire anyway? If the
> answer is 'no', then follow Kostya's suggestion, killing the thread in
> either onPause() or onStop(). If the answer is 'yes', then things get
> more complicated: I suggest putting the timer thread in a Service, not
> an Activity, sending a message to the UI Thread when it fires. Then
> that Thread will display only when it is in the foreground. But then
> you will probably want special logic to handle stale messages when the
> UI Thread executes onResume(). After all, sendMessageAtTime() and
> sendMessageDelayed enqueue the message at that time: they make no
> guarantees about when the Handler Thread will finally actually -
> process- the message. If the Thread has all activities paused, then
> that will be delayed until the right Activity gets an onResume()
> callback.
>
> On Jun 11, 4:15 am, Droid <rod...@gmail.com> wrote:
> > 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.'
> >
> > On Jun 11, 1:02 am, Indicator Veritatis <mej1...@yahoo.com> wrote:
> >
> > > @Droid-
> >
> > > You do realize, I hope, since it is the level of logic that should be
> > > easily expected of any programmer, that what you wrote here makes no
> > > sense.
> >
> > > If, after all, on the one hand, "My thread is a timer thread that
> > > brings my activity back to view after
> > > thehome buttonis pressed". then no, it makes NO sense to "cancel it
> > > whenhome buttonis pressed."
> >
> > > Besides: if it is a timer thread, shouldn't you really mean that it
> > > "bring your activity back to view" after the timer expires? It would
> > > make sense to cancel that timer when Home is pressed. And you can do
> > > that in onPause() or in onStop(). In fact, you should probably do that
> > > in onStop() no matter how you get there This would also simplify your
> > > code, since it is by design that the platform does not TELL you how
> > > you got to onStop(): it certainly does not tell you that it got there
> > > via a Home key.
> >
> > > Also as has been pointed out many times now, overriding the expected
> > > result of the Home key is a really, REALLY bad idea. It is a good
> > > thing that the platform makes this difficult. It should not be done at
> > > all.
> >
> > > Now I realize that some customers insist on this 'feature', even
> > > though it is such a bad idea. In which case, I pity you, but keep on
> > > slogging ahead. It is possible to get close to what you want, either
> > > with a custom Home application or some even more kludgy approach. But
> > > ignore Fung's suggestion, since he is dead wrong.
> >
> > > On Jun 10, 8:52 am, Droid <rod...@gmail.com> wrote:
> >
> > > > My thread is a timer thread that brings my activity back to view
> after
> > > > thehome buttonis pressed. I need to cancel it whenhome buttonis
> > > > pressed.
> > > > (I have 10 activities and no idea in which activity the app was when
> > > > thehome buttonwas pressed)
> >
> > > > On Jun 8, 1:23 pm, TreKing <treking...@gmail.com> wrote:
> >
> > > > > On Wed, Jun 8, 2011 at 1:34 AM, Droid <rod...@gmail.com> wrote:
> > > > > > I have a thread that needs specifically to be cancelled when the
> > > > > >home buttonis pressed.
> >
> > > > > Perhaps if you explain why you think your thread needs to be
> specifically
> > > > > canceled on pressing Home you can get an answer that helps you fix
> your
> > > > > actual problem and not hack around it.
> >
> > > > >
> ---------------------------------------------------------------------------
> ----------------------
> > > > > TreKing <http://sites.google.com/site/rezmobileapps/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
>

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