androidandroid-activityandroid-picture-in-picture

Android onUserLeaveHint() in not called when back button is pressed


I am trying to implement PIP mode and to do so I am overriding onUserLeaveHint() to register events when the user is leaving the activity, but it is not called when the Back button is pressed, it only registers the home or recents button.

    protected void onUserLeaveHint() {
        super.onUserLeaveHint();
        if (usePipMode){
            setUpPipMode();
        }
    }

So, My Question is, Is it possible to register the back button press in onUserLeaveHint(), and if so please provide some code sample. It would be much helpful.

Thanks.


Solution

  • You can do it with onBackPressed method

    @Override
    public void onBackPressed() {
       onUserLeaveHint()
    }