Issue
I inserted into onPause() a call to logout the user; but when i change the orientation of android device the method onPause is invoked same.
WHY? I don't need to invoke the method logoutUser if i turn the device to horizontal/portrait.
Solution
By default Activity
is recreated whenever we change the orientation of the phone. Check Handling Runtime Changes.
Some device configurations can change during runtime (such as screen orientation, keyboard availability, and language). When such a change occurs, Android restarts the running Activity (onDestroy() is called, followed by onCreate())
The reason behind recreation is that the app may want to change the layout based on the new orientation.
But in most cases you don't need to recreate your Activity
each time the user changes phone orientation since you can get callback on your Activity
's onConfigurationChanged()
and make the required layout changes. You can disable them by adding following line in your Activity
tag within your AndroidManifest.xml
file.
android:configChanges="orientation|keyboardHidden|screenSize"
Answered By - Abbas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.