forum

Home / DeveloperSection / Forums / How can I detect user pressing Home button in Android

How can I detect user pressing Home button in Android

Manoj Bhatt 3648 09-Dec-2015
  I have used below code. But its not working.

@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		switch (keyCode) {
		case KeyEvent.KEYCODE_HOME:		

Toast.makeText(getApplicationContext(), "Home button pressed", Toast.LENGTH_SHORT).show();

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

Updated on 27-Jun-2023

Can you answer this question?


Answer

2 Answers

Liked By