Search code examples
javaandroidandroid-activitylockscreenresume

How can i redirect my app to a lock screen when reenter app


My App could be locked with pin or fingerprint. I was able to do this on App Start with an "Start Up" Activity handle the pin/fingerprint stuff. But when it is once handled it is unlocked. But I want that when app was in background the lock screen is shown when the app is resumed. How can i manage this?

I was trying to start an intent when OnResume() of MainActivity is called.

@Override
protected void onResume() {
    super.onResume();

    Intent settingsIntent = new Intent(this, StartUpActivity.class);
    startActivity(settingsIntent);

}

But then it goes to an infinity loop ... :(. And with the resume I can not distinguish whether i came from another activity in my app or if the app was getting back in foreground.

I was also searching a bit but i didn't find a solution to this problem. If i was missed a solution, please provide a link.

Thanks, Sebi


Solution

  • I was able to do the check described in this answer: How to detect when an Android app goes to the background and come back to the foreground

    With this I could check if the app came from the background or from an internal activity. And then I could call the Intent to my Start Up Activity.