Reputation: 101
Is that possible to get notification when Home button is pressed or Home Screen is launched?
In Android Overriding home key thread i read that "it will be notified when the home screen is about to be launched". So is that possible, if yes how?
Thank you
Upvotes: 1
Views: 495
Reputation: 14022
You can Detect Home Screen is running or not
.
You can see this page for more details,Or you can see this answer.It propose use isScreenOn ()
from PowerManager
(Returns whether the screen is currently on. The screen could be bright or dim):
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();
Upvotes: 0
Reputation: 1006674
Is that possible to get notification when Home button is pressed or Home Screen is launched?
Only by being a home screen.
Upvotes: 1
Reputation: 3815
You can simply add this on your activity:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_HOME) {
// Do something
}
return super.onKeyDown(keyCode, event);
}
Upvotes: 0