There is a task for which you need to find out in onDestroy as a result of which the Activity closed, for example, by pressing the "back" button or flipping the screen.
How to find out why, at the moment, the Activity closed?
Essentially, onDestroy() ternary state:
finish() initiated either programmatically or by the axis itselfPerhaps there are other reasons (colleagues will indicate if it is possible).
Pressing back is easily tracked via onBackPressed() , screen rotation via onConfigurationChanged() . If we supplement these methods with the above proposed isFinishing() - then we can completely detect the cause of onDestroy()
For this there is an isFinishing method. If this method returns true then the activation dies, i.e. clicked the back button. If false , then the screen is flipped.
true when finish() is called to activate, and these are more options than just back. And false will be returned in many cases, not only when turning. For example, when you click the Home button, instead of Back, or open another application and many more states. This should be taken into account, everything is not as clear as in your answer (that is, the method is not a turn indicator) - pavlofffSource: https://ru.stackoverflow.com/questions/625949/
All Articles