I am developing an application which request user to enter passcode whenever he/she leave the application or Press home button. This will be applied on all the application activities. i have tried the Activity lifecycle onResume,onRestart and so on. but those will be called when moving from one activity to another activity. i have tried also this code
@Override
public void onUserLeaveHint() {
long uiDelta = (System.currentTimeMillis() - userInteractionTime);
super.onUserLeaveHint();
Log.i("bThere","Last User Interaction = "+uiLag);
if (uiDelta < 100)
Log.i("appname","Home Key Pressed");
else
Log.i("appname","We are leaving, but will probably be back shortly!");
But, this will be called when switching between activities not only when pressing home button.
Any idea on how I can detect leaving the application ?