Search code examples
androidandroid-activityandroid-notification-bar

Handle notification bar folding when Activity still running


Let's say we have a standard MainActivity that extends Activity.

It contains onCreate method that is fired every time when Activity goes on the top (start application, call it again when gone minimized..) - so we can know when user does something outside our application.

Is it possible in any way to check if user expands notification bar (there he enables GPS or screen rotation) and folds it back ?

In this case onCreate is not called because this Activity is still on the top of the stack.


Solution

  • I just got it - symply:

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if ( hasFocus ) {
            doSomething();
        }
    }
    

    solves it (also handles application menu, activities changing, etc - every focus changing).