Hi, Just wanted to check this is still the case. I have a situation where someone wants an application not exit, if the power or home keys are pressed. (They'd like the application to be exited via a password or PIN)
I'm guessing there is no other work around... Regards, Julius. On 11/08/2009, at 3:20 PM, Dianne Hackborn 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 <[email protected]> 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 <[email protected]> wrote: > > The home key is not delivered to applications. > > > > > > > > On Fri, Aug 7, 2009 at 7:25 PM, eags<[email protected]> 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 > [email protected] > > 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 [email protected] > To unsubscribe from this group, send email to > [email protected] > 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

