0

I have an activity that runs asynctasks among other things, I don't want everything to be reset when the layout changes.

I put this in the activity's manifest element android:configChanges="orientation" but unfortunately the activity doesn't even switch from the landscape to portrait layout anymore when that is there!

I only halfway understand saveInstanceStates and passing Bundles around, and I'm definitely not sure how to use that with complex data objects, insight appreciated there

What I would like to do is make sure that the asynctasks don't run again, (I could save variables to disk, and do a conditional check for them before running the asynctask) if there is some android way to really watch out for this that would be great!

thanks

4

3 回答 3

1

我相信这个图书馆一定会达到你的目的

http://brainflush.wordpress.com/2009/11/16/introducing-droid-fu-for-android-betteractivity-betterservice-and-betterasynctask/

于 2011-09-22T01:06:11.440 回答
0

当您放入android:configChanges="orientation"清单时,您声明 android 不需要处理方向更改。因此,定向永远不会发生。

您可以在此线程中查看如何保存值以捆绑 onConfigurationChange(在您的情况下为方向)。如何保存 Android 应用程序的状态?

简而言之,您可以通过覆盖onSaveInstanceState(Bundle savedInstanceState). 通过覆盖onRestoreInstanceState(Bundle savedInstanceState)或检查 bundle 参数来检索您保存到 bundle 的值onCreate

于 2011-09-22T00:45:35.890 回答
0

我决定发布对我有用的东西,这是你的样子吗?这是来自我的清单:

<activity android:name=".MediaSelectActivity" 
android:configChanges="orientation|keyboardHidden" 
android:label="Select Media Item for Vision"
 ></activity>
于 2011-09-22T01:07:36.230 回答