Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android onKeyDown() not execute on pressing back button

Hi after searching on google i come here to ask about help. I use following method to go back when user press back button of device.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {


        Log.i("===BACK BUTTON PRESSED===", "BACK BUTTON");

        return true;
    } else {
        Log.i("===ELSE BACK BUTTON PRESSED===", "ELSE BACK BUTTON");

        return super.onKeyDown(keyCode, event);
    }
}

But logcat does not display any log message.

W/KeyCharacterMap(517): No keyboard for id 0  

W/KeyCharacterMap(517): Using default keymap: /system/usr/keychars/qwerty.kcm.bin Please help me to find this.

EDITED QUESTION :

This is my entire class.

public class Dreams_Reminder_detail_screen extends Activity {   

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        moveTaskToBack(true);
        GroupDreams.group.back();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dreams_reminder_details_screen);        
}

}

like image 775
Hardik Joshi Avatar asked Aug 06 '12 05:08

Hardik Joshi


1 Answers

You can override onBackPressed() function and implement your logic there.

Please refer this android blogpost "Back and other hard keys: three stories" for more understandings.

You can overrided onKeyDown function in GroupDreams perhaps that will work

like image 72
rajpara Avatar answered Sep 18 '22 12:09

rajpara