Is it possible to change this code:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
}
Going to home screen programmatically
to launch home screen
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
Note :
This Intent will start the launcher application that the user has defined. Be careful with this because this will look like your application crashed if the user does not expect this.
If you want this to build an exit button from your app please read this article on exit Buttons in Android