When using the onPause method in the Android SDK, that code is run whenever the Activity was re-drawn (Such as rotating the device). Is there a way to detect whether the Activity was actually paused (Such as a new window popping up) or if the Activity was actually just re-drawn?
Share
Actually if you look at the life cycle of an activity, when the device is rotated, the activity is restarted, so after
onPause(), the activity goes through the complete restart cycle (onStop()andonRestart()are also called), so in this case you can set some value depending on what functions were called, or check the device’s orientation.Also when the activity goes into background,
onPause()is called, and when the activity is no longer visible to the user,onStop()is called, which are due to specific reasons, the application can check that by setting some variable. For complete understanding, study the activity life cycle (Alternate Link)But why do you need to know what happened to the activity? By overriding appropriate functions and providing proper layout resources, you do not need to know what happened in most cases.
For orientation, you can also get the orientation using
getRotationmethod.