[英]IllegalStateException: No activity when onStop() method called
[英]Onstop method is called when Orientation changes
當我更改Android應用程序的方向時,它會調用onStop方法然后調用onCreate。 如何避免在方向改變時調用onStop和onCreate?
這個問題一直很活躍已經有很長時間了,但我需要回答這個問題。 我有同樣的問題並找到答案。
在清單中,你應該在你的活動中添加android:configChanges=orientation|screenLayout|layoutDirection|screenSize
,它們不應該在方向更改時調用默認操作。
...
<activity android:name=".Activity"
android:screenOrientation="portrait"
android:configChanges="orientation|screenLayout|layoutDirection|screenSize"
...
在你的活動中:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// This overrides default action
}
原始示例:
http://android-er.blogspot.fi/2011/05/prevent-activity-restart-when-screen.html
這是默認行為:在方向更改時重新創建活動。 但您可以決定忽略此事件。 您可以在此處找到詳細信息: 如何使應用程序忽略屏幕方向更改?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.