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

CQM
  • 42,592
  • 75
  • 224
  • 366

3 Answers3

1

I believe this library will definitely serve your purpose

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

coder_For_Life22
  • 26,645
  • 20
  • 86
  • 118
0

When you put android:configChanges="orientation" in the manifest, you are declaring that android won't need to handle orientation change. Thus, the orientation never happens.

You can check out how to save value to bundle onConfigurationChange(in your case, orientation) in this thread.How do I save an Android application's state?

In brief, you save some value to bundle by overriding onSaveInstanceState(Bundle savedInstanceState). Retrieve the value you saved to bundle by either overriding onRestoreInstanceState(Bundle savedInstanceState) or checking bundle parameter at onCreate.

Community
  • 1
  • 1
PH7
  • 3,926
  • 3
  • 24
  • 29
  • with `android:configChanges="orientation"` set, how would I force the layout to change due to rendering differneces in landscape and portrait, if I wanted to – CQM Sep 22 '11 at 00:59
  • @PH7 I don't think you are correct about this, my app does re-orient. – Alan Moore Sep 22 '11 at 01:05
  • 2
    http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange This may help you more than I do. The catch is you need to override onConfigurationChanged(Configuration newConfig) and do what you would desire. Be cautious when you handle things by yourself. – PH7 Sep 22 '11 at 01:05
0

I decided to post what is working for me, is this what yours looks like? This is from my manifest:

<activity android:name=".MediaSelectActivity" 
android:configChanges="orientation|keyboardHidden" 
android:label="Select Media Item for Vision"
 ></activity>
Alan Moore
  • 6,525
  • 6
  • 55
  • 68
  • well I've had orientation before, but I do want the layout to change from portrait to landscape and vice versa. When I have that parameter in the activity, this no longer happens when I rotate the device (I didn't add extra classes like onConfigurationChanged though) – CQM Sep 22 '11 at 01:21
  • Do you have separate layouts for land and port? Perhaps that would make a difference here. – Alan Moore Sep 22 '11 at 01:40