How to save and retrieve variables upon screen rotation?
NickName:user2709498 Ask DateTime:2013-08-23T11:32:30

How to save and retrieve variables upon screen rotation?

Can someone kindly give me a solution to this and explain how he/she came to that particular solution? Thanks so much

1) Upon rotation of the GUI from portrait to landscape or the opposite disappears all local variables.Write content of the class, where it is marked with To-Do, so that variable isGameFinished taken care of by rotation and collected again when the app is rotated

Class

public class StatteActivity extends Activity{

private boolean isGameFinished;
private Button buttonFinishGame;

protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_state);

//Get previous state for isGameFinished if it exists
//TO-DO

//Find button
buttonFinishGame = (Button) findViewByID(R.id.buttonFinishGame);
buttonFinishGame.setOnClickListener(new OnClickListener(){
public void onClick(View v){
isGameFinished = true;
}
});

if(isGameFinished){
finish();
}
}

protected void onSaveInstanceState(Bundle outState){
//To-Do
super.onSaveInstanceState(outState);
}
}

Copyright Notice:Content Author:「user2709498」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/18394274/how-to-save-and-retrieve-variables-upon-screen-rotation

More about “How to save and retrieve variables upon screen rotation?” related questions

How to save and retrieve variables upon screen rotation?

Can someone kindly give me a solution to this and explain how he/she came to that particular solution? Thanks so much 1) Upon rotation of the GUI from portrait to landscape or the opposite disapp...

Show Detail

Original intent bundle retained upon screen rotation?

Is the original info passed to an activity at creation (e.g. an Intent Bundle from getIntent().getExtras()) retained when the screen orientation is changed? Can I just call getIntent().getExtras()...

Show Detail

Screen gets cut and hangs for few seconds upon rotation

My windows 8 store xaml app gets cut in half upon rotation from landscape mode to Portrait mode and vice versa. Upon rotation the screen gets hanged for a second and gets cut. After a pause of arou...

Show Detail

Android save Activity data during screen rotation

I google a lot, but now I decided to ask.. My activity does only one simple thing - it downloads a picture from Internet using AsyncTask. But there is a lot of problems, that I am not sure, how to

Show Detail

Android: Save variables and settings on rotation

Is there a way to save variables that are being changed in the code, when the screen rotates? Thank you in advance

Show Detail

How to save and then retrieve all window variables in JS?

the JS script uses: window.opener.variables since variables are stored on the windows that opened the popup. My goal is to avoid to use the popup, but keep the script as it is. Idea1: I try to s...

Show Detail

How to save the fields data while changing the Layout on screen rotation

I have read a lot of things about the data save instance and restore but Unable to implement in my case. What is my case in application . I am using the Activity (MainActivity) and calling the fr...

Show Detail

Save data in Fragments on screen rotation in Android

Can anyone help me to solve my problem? I have an activity and six fragments. One fragment contains a link to my MediaPlayer class, which I use to show some video in a fragment. I get a link for

Show Detail

WkWebView reloads Youtube video upon rotation

I currently have a WKWebView which plays YouTube videos inline. Upon rotation to horizontal orientation, I have the view change constraints to full screen - however, this causes the YouTube video i...

Show Detail

How to retrieve the PdfStampAnnotation rotation

Referring to How to retrieve the image of a PdfStampAnnotation, how to retrieve the rotation of an stamp annotation ? I create a document, put a stamp1, turn the page and add another stamp2. The

Show Detail