Saving android activity state












2















I just learned Android programming, and i have a problem.



I create an activity with a checkbox widget that is added programmatically or the checkbox widget will be added if the user touches the add button(tambah), the problem is how to save the state activity?



MainActivity.java



public class MainActivity extends Activity {

// Variable Global
int checkId = 0; //CheckBox Id
EditText ex;
TextView noText;
LinearLayout m;
CheckBox check;
CheckBox noCheck;
String dat;
Toast errorNot;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void funcOne(View view) {

/**
* tambah.onClick function
* @param ex - EditText variable
* @param noText - TextView variable used for spacing
* @param m - CheckBox main layout
* @param check - Generated CheckBox widget
* @param noCheck - Toggle between CheckBox and EditText
* @param dat - EditText variable converted to String
* @param errorNot - To display noData error
*/

ex = (EditText)findViewById(R.id.editData);
noText = new TextView(this);
m = (LinearLayout)findViewById(R.id.checkBoxLayout);
check = new CheckBox(this);
noCheck = (CheckBox)findViewById(R.id.noCheck);
dat = ex.getText().toString();
errorNot = Toast.makeText(this, "No input data", Toast.LENGTH_LONG);

// Method
if (dat.length() > 1) {
if (noCheck.isChecked()) {
noText.setText(dat);
m.addView(noText);
} else {

/**
* @param n - New Toast (Only for debugging)
*/

checkId ++;
Toast n = Toast.makeText(this, Integer.toString(checkId), Toast.LENGTH_SHORT);
check.setTag("ch"+checkId);
check.setText(dat + " <WidgetTag " +check.getTag() + ">");
m.addView(check);
n.show();
}
} else {
errorNot.show();
}
}

public void addSpace(View view) {

/**
* space.onClick function
* @param b - Child layout
* @param d - TextView
*/

LinearLayout b = (LinearLayout)findViewById(R.id.checkBoxLayout);
TextView d = new TextView(this);
b.addView(d);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
//outState.putBoolean("AstringKey", noCheck);
outState.putString("AStringKey2", dat);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
//savedInstanceState.getBoolean("AStringKey");
savedInstanceState.getString("AStringKey2");
}


App Layout:
http://imgur.com/gallery/1ZfJ5QL










share|improve this question

























  • Paste your code here instead of in the image you posted

    – Cool Guy CG
    Nov 13 '18 at 8:36











  • What do you mean with saving state? Like when you close the app again or when your activity gets restarted (where savedInstanceState != null)?

    – finki
    Nov 13 '18 at 9:48
















2















I just learned Android programming, and i have a problem.



I create an activity with a checkbox widget that is added programmatically or the checkbox widget will be added if the user touches the add button(tambah), the problem is how to save the state activity?



MainActivity.java



public class MainActivity extends Activity {

// Variable Global
int checkId = 0; //CheckBox Id
EditText ex;
TextView noText;
LinearLayout m;
CheckBox check;
CheckBox noCheck;
String dat;
Toast errorNot;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void funcOne(View view) {

/**
* tambah.onClick function
* @param ex - EditText variable
* @param noText - TextView variable used for spacing
* @param m - CheckBox main layout
* @param check - Generated CheckBox widget
* @param noCheck - Toggle between CheckBox and EditText
* @param dat - EditText variable converted to String
* @param errorNot - To display noData error
*/

ex = (EditText)findViewById(R.id.editData);
noText = new TextView(this);
m = (LinearLayout)findViewById(R.id.checkBoxLayout);
check = new CheckBox(this);
noCheck = (CheckBox)findViewById(R.id.noCheck);
dat = ex.getText().toString();
errorNot = Toast.makeText(this, "No input data", Toast.LENGTH_LONG);

// Method
if (dat.length() > 1) {
if (noCheck.isChecked()) {
noText.setText(dat);
m.addView(noText);
} else {

/**
* @param n - New Toast (Only for debugging)
*/

checkId ++;
Toast n = Toast.makeText(this, Integer.toString(checkId), Toast.LENGTH_SHORT);
check.setTag("ch"+checkId);
check.setText(dat + " <WidgetTag " +check.getTag() + ">");
m.addView(check);
n.show();
}
} else {
errorNot.show();
}
}

public void addSpace(View view) {

/**
* space.onClick function
* @param b - Child layout
* @param d - TextView
*/

LinearLayout b = (LinearLayout)findViewById(R.id.checkBoxLayout);
TextView d = new TextView(this);
b.addView(d);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
//outState.putBoolean("AstringKey", noCheck);
outState.putString("AStringKey2", dat);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
//savedInstanceState.getBoolean("AStringKey");
savedInstanceState.getString("AStringKey2");
}


App Layout:
http://imgur.com/gallery/1ZfJ5QL










share|improve this question

























  • Paste your code here instead of in the image you posted

    – Cool Guy CG
    Nov 13 '18 at 8:36











  • What do you mean with saving state? Like when you close the app again or when your activity gets restarted (where savedInstanceState != null)?

    – finki
    Nov 13 '18 at 9:48














2












2








2








I just learned Android programming, and i have a problem.



I create an activity with a checkbox widget that is added programmatically or the checkbox widget will be added if the user touches the add button(tambah), the problem is how to save the state activity?



MainActivity.java



public class MainActivity extends Activity {

// Variable Global
int checkId = 0; //CheckBox Id
EditText ex;
TextView noText;
LinearLayout m;
CheckBox check;
CheckBox noCheck;
String dat;
Toast errorNot;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void funcOne(View view) {

/**
* tambah.onClick function
* @param ex - EditText variable
* @param noText - TextView variable used for spacing
* @param m - CheckBox main layout
* @param check - Generated CheckBox widget
* @param noCheck - Toggle between CheckBox and EditText
* @param dat - EditText variable converted to String
* @param errorNot - To display noData error
*/

ex = (EditText)findViewById(R.id.editData);
noText = new TextView(this);
m = (LinearLayout)findViewById(R.id.checkBoxLayout);
check = new CheckBox(this);
noCheck = (CheckBox)findViewById(R.id.noCheck);
dat = ex.getText().toString();
errorNot = Toast.makeText(this, "No input data", Toast.LENGTH_LONG);

// Method
if (dat.length() > 1) {
if (noCheck.isChecked()) {
noText.setText(dat);
m.addView(noText);
} else {

/**
* @param n - New Toast (Only for debugging)
*/

checkId ++;
Toast n = Toast.makeText(this, Integer.toString(checkId), Toast.LENGTH_SHORT);
check.setTag("ch"+checkId);
check.setText(dat + " <WidgetTag " +check.getTag() + ">");
m.addView(check);
n.show();
}
} else {
errorNot.show();
}
}

public void addSpace(View view) {

/**
* space.onClick function
* @param b - Child layout
* @param d - TextView
*/

LinearLayout b = (LinearLayout)findViewById(R.id.checkBoxLayout);
TextView d = new TextView(this);
b.addView(d);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
//outState.putBoolean("AstringKey", noCheck);
outState.putString("AStringKey2", dat);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
//savedInstanceState.getBoolean("AStringKey");
savedInstanceState.getString("AStringKey2");
}


App Layout:
http://imgur.com/gallery/1ZfJ5QL










share|improve this question
















I just learned Android programming, and i have a problem.



I create an activity with a checkbox widget that is added programmatically or the checkbox widget will be added if the user touches the add button(tambah), the problem is how to save the state activity?



MainActivity.java



public class MainActivity extends Activity {

// Variable Global
int checkId = 0; //CheckBox Id
EditText ex;
TextView noText;
LinearLayout m;
CheckBox check;
CheckBox noCheck;
String dat;
Toast errorNot;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void funcOne(View view) {

/**
* tambah.onClick function
* @param ex - EditText variable
* @param noText - TextView variable used for spacing
* @param m - CheckBox main layout
* @param check - Generated CheckBox widget
* @param noCheck - Toggle between CheckBox and EditText
* @param dat - EditText variable converted to String
* @param errorNot - To display noData error
*/

ex = (EditText)findViewById(R.id.editData);
noText = new TextView(this);
m = (LinearLayout)findViewById(R.id.checkBoxLayout);
check = new CheckBox(this);
noCheck = (CheckBox)findViewById(R.id.noCheck);
dat = ex.getText().toString();
errorNot = Toast.makeText(this, "No input data", Toast.LENGTH_LONG);

// Method
if (dat.length() > 1) {
if (noCheck.isChecked()) {
noText.setText(dat);
m.addView(noText);
} else {

/**
* @param n - New Toast (Only for debugging)
*/

checkId ++;
Toast n = Toast.makeText(this, Integer.toString(checkId), Toast.LENGTH_SHORT);
check.setTag("ch"+checkId);
check.setText(dat + " <WidgetTag " +check.getTag() + ">");
m.addView(check);
n.show();
}
} else {
errorNot.show();
}
}

public void addSpace(View view) {

/**
* space.onClick function
* @param b - Child layout
* @param d - TextView
*/

LinearLayout b = (LinearLayout)findViewById(R.id.checkBoxLayout);
TextView d = new TextView(this);
b.addView(d);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
//outState.putBoolean("AstringKey", noCheck);
outState.putString("AStringKey2", dat);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
//savedInstanceState.getBoolean("AStringKey");
savedInstanceState.getString("AStringKey2");
}


App Layout:
http://imgur.com/gallery/1ZfJ5QL







java android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 8:52







user10644931

















asked Nov 13 '18 at 8:33









user10644931user10644931

112




112













  • Paste your code here instead of in the image you posted

    – Cool Guy CG
    Nov 13 '18 at 8:36











  • What do you mean with saving state? Like when you close the app again or when your activity gets restarted (where savedInstanceState != null)?

    – finki
    Nov 13 '18 at 9:48



















  • Paste your code here instead of in the image you posted

    – Cool Guy CG
    Nov 13 '18 at 8:36











  • What do you mean with saving state? Like when you close the app again or when your activity gets restarted (where savedInstanceState != null)?

    – finki
    Nov 13 '18 at 9:48

















Paste your code here instead of in the image you posted

– Cool Guy CG
Nov 13 '18 at 8:36





Paste your code here instead of in the image you posted

– Cool Guy CG
Nov 13 '18 at 8:36













What do you mean with saving state? Like when you close the app again or when your activity gets restarted (where savedInstanceState != null)?

– finki
Nov 13 '18 at 9:48





What do you mean with saving state? Like when you close the app again or when your activity gets restarted (where savedInstanceState != null)?

– finki
Nov 13 '18 at 9:48












2 Answers
2






active

oldest

votes


















1














There is a Bundle parameter for onCreate() method in each activity. You can save instance in that. You can write code in onPause() so that before finishing activity it will store your content. You can again access it by using same bundle






share|improve this answer
























  • So I need onPause() ? Because I have written onSaveInstanceState(), but nothing happen

    – user10644931
    Nov 13 '18 at 8:42



















0














There are 2 methods available that can help you achieve this.



    @Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
super.onSaveInstanceState(outState, outPersistentState);
// save your data into either or both of the parameters with the put### methods
}


This method allows your activity to retain some of its data even after reboot. The data that you want to retain after reboot can be stored in the PersistableBundle object. The Bundle object is used in the same way as the one below.
This method however requires that some attributes be set on when you are starting this activity, you can read more on this in the android sdk documentation.



     @Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// save your data into either or both of the parameters with the put### methods
}


This method only allows your activity to retain some data, but all the data will be cleared after a reboot. You can store all your necessary data in the Bundle object. This bundle will then be passed into your onCreate method the next time you return to this activity, provided you didn't destroy the activity instance.



The mistake in your code however is this;



@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
//savedInstanceState.getBoolean("AStringKey");
savedInstanceState.getString("AStringKey2");// you are not assigning this to the dat variable.
// it should rather be
dat = savedInstanceState.getString("AStringKey2");
}





share|improve this answer


























  • I already add that code, but nothing happen

    – user10644931
    Nov 13 '18 at 8:54











  • Read my updated answer

    – Cool Guy CG
    Nov 13 '18 at 8:56











  • I'm sorry, but that also doesn't work

    – user10644931
    Nov 13 '18 at 9:54











  • Are you pressing the back key? If not, then try and do a debug by placing breakpoints at where ever the dat variable was used.

    – Cool Guy CG
    Nov 13 '18 at 10:59











  • The problem is: when the application changes orientation, the checkbox widget disappears, I try to press the back button, then open the application, there is no checkbox widget, the application is empty

    – user10644931
    Nov 13 '18 at 11:10











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276831%2fsaving-android-activity-state%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














There is a Bundle parameter for onCreate() method in each activity. You can save instance in that. You can write code in onPause() so that before finishing activity it will store your content. You can again access it by using same bundle






share|improve this answer
























  • So I need onPause() ? Because I have written onSaveInstanceState(), but nothing happen

    – user10644931
    Nov 13 '18 at 8:42
















1














There is a Bundle parameter for onCreate() method in each activity. You can save instance in that. You can write code in onPause() so that before finishing activity it will store your content. You can again access it by using same bundle






share|improve this answer
























  • So I need onPause() ? Because I have written onSaveInstanceState(), but nothing happen

    – user10644931
    Nov 13 '18 at 8:42














1












1








1







There is a Bundle parameter for onCreate() method in each activity. You can save instance in that. You can write code in onPause() so that before finishing activity it will store your content. You can again access it by using same bundle






share|improve this answer













There is a Bundle parameter for onCreate() method in each activity. You can save instance in that. You can write code in onPause() so that before finishing activity it will store your content. You can again access it by using same bundle







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 8:35









The90sArtistThe90sArtist

417




417













  • So I need onPause() ? Because I have written onSaveInstanceState(), but nothing happen

    – user10644931
    Nov 13 '18 at 8:42



















  • So I need onPause() ? Because I have written onSaveInstanceState(), but nothing happen

    – user10644931
    Nov 13 '18 at 8:42

















So I need onPause() ? Because I have written onSaveInstanceState(), but nothing happen

– user10644931
Nov 13 '18 at 8:42





So I need onPause() ? Because I have written onSaveInstanceState(), but nothing happen

– user10644931
Nov 13 '18 at 8:42













0














There are 2 methods available that can help you achieve this.



    @Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
super.onSaveInstanceState(outState, outPersistentState);
// save your data into either or both of the parameters with the put### methods
}


This method allows your activity to retain some of its data even after reboot. The data that you want to retain after reboot can be stored in the PersistableBundle object. The Bundle object is used in the same way as the one below.
This method however requires that some attributes be set on when you are starting this activity, you can read more on this in the android sdk documentation.



     @Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// save your data into either or both of the parameters with the put### methods
}


This method only allows your activity to retain some data, but all the data will be cleared after a reboot. You can store all your necessary data in the Bundle object. This bundle will then be passed into your onCreate method the next time you return to this activity, provided you didn't destroy the activity instance.



The mistake in your code however is this;



@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
//savedInstanceState.getBoolean("AStringKey");
savedInstanceState.getString("AStringKey2");// you are not assigning this to the dat variable.
// it should rather be
dat = savedInstanceState.getString("AStringKey2");
}





share|improve this answer


























  • I already add that code, but nothing happen

    – user10644931
    Nov 13 '18 at 8:54











  • Read my updated answer

    – Cool Guy CG
    Nov 13 '18 at 8:56











  • I'm sorry, but that also doesn't work

    – user10644931
    Nov 13 '18 at 9:54











  • Are you pressing the back key? If not, then try and do a debug by placing breakpoints at where ever the dat variable was used.

    – Cool Guy CG
    Nov 13 '18 at 10:59











  • The problem is: when the application changes orientation, the checkbox widget disappears, I try to press the back button, then open the application, there is no checkbox widget, the application is empty

    – user10644931
    Nov 13 '18 at 11:10
















0














There are 2 methods available that can help you achieve this.



    @Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
super.onSaveInstanceState(outState, outPersistentState);
// save your data into either or both of the parameters with the put### methods
}


This method allows your activity to retain some of its data even after reboot. The data that you want to retain after reboot can be stored in the PersistableBundle object. The Bundle object is used in the same way as the one below.
This method however requires that some attributes be set on when you are starting this activity, you can read more on this in the android sdk documentation.



     @Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// save your data into either or both of the parameters with the put### methods
}


This method only allows your activity to retain some data, but all the data will be cleared after a reboot. You can store all your necessary data in the Bundle object. This bundle will then be passed into your onCreate method the next time you return to this activity, provided you didn't destroy the activity instance.



The mistake in your code however is this;



@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
//savedInstanceState.getBoolean("AStringKey");
savedInstanceState.getString("AStringKey2");// you are not assigning this to the dat variable.
// it should rather be
dat = savedInstanceState.getString("AStringKey2");
}





share|improve this answer


























  • I already add that code, but nothing happen

    – user10644931
    Nov 13 '18 at 8:54











  • Read my updated answer

    – Cool Guy CG
    Nov 13 '18 at 8:56











  • I'm sorry, but that also doesn't work

    – user10644931
    Nov 13 '18 at 9:54











  • Are you pressing the back key? If not, then try and do a debug by placing breakpoints at where ever the dat variable was used.

    – Cool Guy CG
    Nov 13 '18 at 10:59











  • The problem is: when the application changes orientation, the checkbox widget disappears, I try to press the back button, then open the application, there is no checkbox widget, the application is empty

    – user10644931
    Nov 13 '18 at 11:10














0












0








0







There are 2 methods available that can help you achieve this.



    @Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
super.onSaveInstanceState(outState, outPersistentState);
// save your data into either or both of the parameters with the put### methods
}


This method allows your activity to retain some of its data even after reboot. The data that you want to retain after reboot can be stored in the PersistableBundle object. The Bundle object is used in the same way as the one below.
This method however requires that some attributes be set on when you are starting this activity, you can read more on this in the android sdk documentation.



     @Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// save your data into either or both of the parameters with the put### methods
}


This method only allows your activity to retain some data, but all the data will be cleared after a reboot. You can store all your necessary data in the Bundle object. This bundle will then be passed into your onCreate method the next time you return to this activity, provided you didn't destroy the activity instance.



The mistake in your code however is this;



@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
//savedInstanceState.getBoolean("AStringKey");
savedInstanceState.getString("AStringKey2");// you are not assigning this to the dat variable.
// it should rather be
dat = savedInstanceState.getString("AStringKey2");
}





share|improve this answer















There are 2 methods available that can help you achieve this.



    @Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
super.onSaveInstanceState(outState, outPersistentState);
// save your data into either or both of the parameters with the put### methods
}


This method allows your activity to retain some of its data even after reboot. The data that you want to retain after reboot can be stored in the PersistableBundle object. The Bundle object is used in the same way as the one below.
This method however requires that some attributes be set on when you are starting this activity, you can read more on this in the android sdk documentation.



     @Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// save your data into either or both of the parameters with the put### methods
}


This method only allows your activity to retain some data, but all the data will be cleared after a reboot. You can store all your necessary data in the Bundle object. This bundle will then be passed into your onCreate method the next time you return to this activity, provided you didn't destroy the activity instance.



The mistake in your code however is this;



@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
//savedInstanceState.getBoolean("AStringKey");
savedInstanceState.getString("AStringKey2");// you are not assigning this to the dat variable.
// it should rather be
dat = savedInstanceState.getString("AStringKey2");
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 '18 at 8:56

























answered Nov 13 '18 at 8:48









Cool Guy CGCool Guy CG

71048




71048













  • I already add that code, but nothing happen

    – user10644931
    Nov 13 '18 at 8:54











  • Read my updated answer

    – Cool Guy CG
    Nov 13 '18 at 8:56











  • I'm sorry, but that also doesn't work

    – user10644931
    Nov 13 '18 at 9:54











  • Are you pressing the back key? If not, then try and do a debug by placing breakpoints at where ever the dat variable was used.

    – Cool Guy CG
    Nov 13 '18 at 10:59











  • The problem is: when the application changes orientation, the checkbox widget disappears, I try to press the back button, then open the application, there is no checkbox widget, the application is empty

    – user10644931
    Nov 13 '18 at 11:10



















  • I already add that code, but nothing happen

    – user10644931
    Nov 13 '18 at 8:54











  • Read my updated answer

    – Cool Guy CG
    Nov 13 '18 at 8:56











  • I'm sorry, but that also doesn't work

    – user10644931
    Nov 13 '18 at 9:54











  • Are you pressing the back key? If not, then try and do a debug by placing breakpoints at where ever the dat variable was used.

    – Cool Guy CG
    Nov 13 '18 at 10:59











  • The problem is: when the application changes orientation, the checkbox widget disappears, I try to press the back button, then open the application, there is no checkbox widget, the application is empty

    – user10644931
    Nov 13 '18 at 11:10

















I already add that code, but nothing happen

– user10644931
Nov 13 '18 at 8:54





I already add that code, but nothing happen

– user10644931
Nov 13 '18 at 8:54













Read my updated answer

– Cool Guy CG
Nov 13 '18 at 8:56





Read my updated answer

– Cool Guy CG
Nov 13 '18 at 8:56













I'm sorry, but that also doesn't work

– user10644931
Nov 13 '18 at 9:54





I'm sorry, but that also doesn't work

– user10644931
Nov 13 '18 at 9:54













Are you pressing the back key? If not, then try and do a debug by placing breakpoints at where ever the dat variable was used.

– Cool Guy CG
Nov 13 '18 at 10:59





Are you pressing the back key? If not, then try and do a debug by placing breakpoints at where ever the dat variable was used.

– Cool Guy CG
Nov 13 '18 at 10:59













The problem is: when the application changes orientation, the checkbox widget disappears, I try to press the back button, then open the application, there is no checkbox widget, the application is empty

– user10644931
Nov 13 '18 at 11:10





The problem is: when the application changes orientation, the checkbox widget disappears, I try to press the back button, then open the application, there is no checkbox widget, the application is empty

– user10644931
Nov 13 '18 at 11:10


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276831%2fsaving-android-activity-state%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Hercules Kyvelos

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud