android - Which method is preferred to override onBackPressed? -
first case
public boolean onkeydown(int keycode, keyevent event) { if (keycode == keyevent.keycode_back) {
second case
onbackpressed();
which case improve override backkeypress event?
if want grab press prior 2.0, can utilize onkeydown
method so:
@override public boolean onkeydown(int keycode, keyevent event) { if (keycode == keyevent.keycode_back && event.getrepeatcount() == 0) { //do on press } homecoming super.onkeydown(keycode, event); }
interestingly, if override both onbackpressed , onkeydown, both grab press onkeydown
catching first.
if phone call super.onkeydown
in onkeydown
above, onbackpressed
method fire. if not phone call super.onkeydown
onbackpressed
never called.
unless have specific reason target below 2.0, there isn’t much of reason bother.
android
No comments:
Post a Comment