Prevent login screen on screen rotation android

前端 未结 2 661

I have an application in which a login screen shows up whenever an activity goes to onPause state. Generally, when screen orientation changes, the activity goes to onPause state

2条回答
  •  误落风尘
    2021-01-28 09:42

    By default, Android will actually destroy and restart your activity on rotation. This causes onPause(), onStop(), onDestroy(), onCreate(), onStart(), onResume() to be called. The best way to avoid problems like this is to tell Android not to do that. In the manifest add android:configChange="orientation" to your Activity. It will prevent the destruction, and call a function on rotation instead. It will still correctly redraw your screen in almost all cases.

提交回复
热议问题