在我的活动中,我有一个名为A
extends的内部类AsyncTask
。我不希望活动在设备旋转时再次破坏和重新创建。我希望它继续运行。我已阅读此链接RotationAsync
。他们使用 AsyncTask 的静态类。我在我的活动中声明了许多变量,所以如果我使用静态类,我不能使用活动变量。是否有另一种方法可以在不使用静态类的情况下执行上述链接AsyncTask
?感谢您的回答。对不起,如果我的英语有一些错误。
问问题
263 次
2 回答
1
您可以使用 Manifest 上的此设置来阻止您的 Activity 重新启动:
<activity android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name">
之后,您可以使用此代码管理更改
@Override public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
//do something here
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
//do something here
}
}
有关更多信息,您可以阅读http://developer.android.com/guide/topics/resources/runtime-changes.html
于 2011-12-05T15:03:11.747 回答
0
为了保留您的变量,您可以将它们保存到一个 Bundle 中,并在重新创建 Activity 时重新加载它的状态。这应该让你开始:http: //developer.android.com/guide/topics/fundamentals/activities.html#SavingActivityState
于 2011-12-05T14:38:01.693 回答