Thanks Dianne.   I am still confused as to why consuming all events in
onKeyDown breaks the normal behavior when relaunching the app?  If I
leave onKeyDown alone, pressing HOME takes me to the home screen and
relaunching takes me directly back to where I left off in the task.
However if I always return true from onKeyDown then after pressing
home and then relaunching, the task is restarted from the beginning.
Why is that?

Thanks again.

On Aug 10, 8:20 pm, Dianne Hackborn <hack...@android.com> wrote:
> The home and end call keys are intercepted by the system before ever
> reaching the application, and there is nothing you can do in the app to
> modify their behavior (including overriding onKeyDown).
>
> All other keys (including back, menu, call, and search) are first sent to
> the application and only perform their default action if the application
> does not consume them.  By returning true from onKeyDown(), you are
> consuming the events and not allowing their normal behavior to run.
>
>
>
>
>
> On Mon, Aug 10, 2009 at 7:15 PM, eags <eagsala...@gmail.com> wrote:
>
> > This behavior is actually very strange and apparently not quite as
> > simple as the event is not delivered to applications.
>
> > Indeed if I try and capture the key event, I cannot.  However if I
> > just do this:
>
> >    public boolean onKeyDown(int keyCode, KeyEvent event)
> >    {
> >         return true;
> >        //return super.onKeyDown(keyCode, event);
> >    }
>
> > and then press the home key, the Activity does not stay in the task
> > stack and launching again does not get me back to this activity but
> > the whole app is just launched again from the beginning.  So it is
> > like there is something in the default implementation of onKeyDown
> > that makes the correct behavior work and I can't stop it from
> > happening but somehow I can break it but always retuning true from
> > onKeyDown.
>
> > Can anyone explain this behavior or point me to some documentation
> > that will clear this up?
>
> > Thanks.
>
> > On Aug 7, 8:04 pm, Marco Nelissen <marc...@android.com> wrote:
> > > The home key is not delivered to applications.
>
> > > On Fri, Aug 7, 2009 at 7:25 PM, eags<eagsala...@gmail.com> wrote:
>
> > > > I have implemented onKeyDown and can successfully intercept
> > > > KEYCODE_BACK and many others to prohibit the default behavior.  Is
> > > > this not possible with KEYCODE_HOME?  I have a test activity that will
> > > > only finish() if KEYCODE_A is seen.  Even KEYCODE_BACK does nothing.
> > > > However KEYCODE_HOME continues to have its effect.
>
> > > > Anyone have any insight into this?
>
> > > > Thanks.  The test code is below.  The strange thing to note is that
> > > > although the toast in the if/else that should handle the KEYCODE_HOME
> > > > never fires, if I relaunch the application the state is *not* restored
> > > > so it is like either the onDestroy is being called (previously I tried
> > > > finish() also) or it is like the application is crashing for some
> > > > other reason.
>
> > > > I'm confused.
>
> > > > import android.app.Activity;
> > > > import android.os.Bundle;
> > > > import android.view.KeyEvent;
> > > > import android.widget.Toast;
>
> > > > public class MainMenu extends Activity
> > > > {
> > > >        public void onCreate(Bundle bun)
> > > >        {
> > > >                super.onCreate(bun);
> > > >                setContentView(R.layout.main);
>
> > > >        }
> > > >    public boolean onKeyDown(int keyCode, KeyEvent event)
> > > >    {
> > > >        //if we get any key, clear the Splash Screen
> > > >        if(keyCode==KeyEvent.KEYCODE_HOME) {
> > > >                Toast.makeText(getApplicationContext(), "HIT!",
> > > > Toast.LENGTH_SHORT).show();
> > > >                onDestroy();
> > > >                return true;
> > > >        } else {
> > > >                Toast.makeText(getApplicationContext(), "missed",
> > > > Toast.LENGTH_SHORT).show();
> > > >                return true;
> > > >        }
> > > >        //return super.onKeyDown(keyCode, event);
> > > >    }
>
> > > > }
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails.  All such
> questions should be posted on public forums, where I and others can see and
> answer them.
--~--~---------~--~----~------------~-------~--~----~
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