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); > > } > > > } --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---