Is it possible to somehow determine in the application that the notification bar is lowered and closes some part of the activity?

  • no, maximum, maybe at this moment Activity goes to the background, and the onPause method is called - Vladyslav Matviienko
  • one
    onPause does not twitch, that's just the point - gcoder

2 answers 2

Also suffered with this. As a result, the use of the overridden method public void onWindowFocusChanged(boolean hasFocus) activity came up for my case.

It was important for me to track when the activity loses focus, including the status bar is lowered.

  @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (!hasFocus) { // Действия при потере фокуса приложением (в т.ч. при опускании статус бара) } } 

Here is an example of how I control the behavior of an activity when a user interacts with a status bar, and intercepts the focus with other activities.

 @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (gameFragment!=null) { if (!hasFocus) { if (frag == gameFragment) { gameFragment.saveTimer(); isTimerPaused = true; Log.i("TAG", "MainActivity onWindowFocusChanged isTimerPaused " + isTimerPaused); } } else if (isTimerPaused) { gameFragment.loadTimer(); isTimerPaused = false; Log.i("TAG", "MainActivity onWindowFocusChanged isTimerPaused " + isTimerPaused); } } } 

If such a general method works, well) Because I didn’t find how to intercept the curtain lowering event .. I will be glad if knowledgeable people add in the comments how to improve or change my way of solving the problem.

    You do not have access to the notification curtain, this system application is responsible for it. OnPause your activate at this moment will not be called.