Friday, June 10, 2011

[android-developers] Re: How can I know when the home button has been pressed?

@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
the home button is pressed". then no, it makes NO sense to "cancel it
when home button is 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
> the home button is pressed. I need to cancel it when home button is
> pressed.
> (I have 10 activities and no idea in which activity the app was when
> the home button was 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 button is 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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment