当我更改Android应用程序的方向时,它会调用onStop方法然后调用onCreate.如何避免在方向改变时调用onStop和onCreate?
这个问题一直很活跃已经有很长时间了,但我需要回答这个问题.我有同样的问题并找到答案.
在清单中,您应该添加android:configChanges=orientation|screenLayout|layoutDirection|screenSize您的活动,该活动不应在方向更改上调用默认操作.
...
<activity android:name=".Activity"
android:screenOrientation="portrait"
android:configChanges="orientation|screenLayout|layoutDirection|screenSize"
...
Run Code Online (Sandbox Code Playgroud)
在你的活动中:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// This overrides default action
}
Run Code Online (Sandbox Code Playgroud)
原始示例:http:
//android-er.blogspot.fi/2011/05/prevent-activity-restart-when-screen.html
| 归档时间: |
|
| 查看次数: |
4215 次 |
| 最近记录: |