this question has answer here:
- set action home button in android 3 answers
i making app privacy of utmost importance. so, there password enter app. now, problem lies when user presses home button - then, happens current task taken background , android home screen displayed.
but when user clicks on app's icon on android device, app returns same private state without asking password.
i want make app start @ login activity when app's icon pressed.
in each , every 1 of activities, have following code:
if ((keycode == keyevent.keycode_home)) { toast.maketext(this, "you pressed home button!", toast.length_long).show(); return true; } return super.onkeydown(keycode, event);
but, toast never getting displayed...similarly, tried
finish();
the process in code. doesn't happen. not possible control home button does, or missing out?
thanks!
it not possible.
there no way intercept home button on android, unless make app home screen. security reasons, malicious apps cannot take on device overriding buttons can exit.
if want handle home button, implement home screen.
but suggest rethink design. leave option of logout user.
http://developer.android.com/training/design-navigation/index.html
look @ gmail app. when press home button not logout.
@override protected void onuserleavehint() { super.onuserleavehint(); toast.maketext(this, "you pressed home button!", toast.length_long).show(); log.i("home button pressed!", "yes"); finish(); }
you can use onuserleavehint
protected void onuserleavehint ()
added in api level 3
called part of activity lifecycle when activity go background result of user choice. for example, when user presses home key, onuserleavehint() called, when incoming phone call causes in-call activity automatically brought foreground, onuserleavehint() not called on activity being interrupted. in cases when invoked, method called right before activity's onpause() callback.
this callback , onuserinteraction() intended activities manage status bar notifications intelligently; specifically, helping activities determine proper time cancel notfication.
Comments
Post a Comment