CQM
CQM

Reputation: 44230

Android save certain values on rotation

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

Upvotes: 0

Views: 1110

Answers (3)

Alan Moore
Alan Moore

Reputation: 6575

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>

Upvotes: 0

PH7
PH7

Reputation: 3916

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.

Upvotes: 0

Related Questions