---
title: "Checkbox status is not saving in android"  
description: "Checkbox status is not saving in android"  
author: "Anonymous User"  
published: 2014-10-20  
updated: 2014-10-20  
canonical: https://www.mindstick.com/forum/2420/checkbox-status-is-not-saving-in-android  
category: "android"  
tags: ["android"]  
reading_time: 2 minutes  

---

# Checkbox status is not saving in android

I'm developing task list [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) using sharedpreferences. but it doesn't save [checkbox](https://www.mindstick.com/articles/291/how-should-use-checkbox-control-in-vb-dot-net) [status](https://www.mindstick.com/articles/157184/check-lic-policy-status-online-by-policy-number). I want to save when user click on checkbox. After user exits the application and see again it is [already](https://yourviews.mindstick.com/view/88453/the-hidden-ways-ai-is-already-controlling-your-daily-life) updated status. How to save checkbox status? Here is my code (Already Fixed and Working)\

public class TaskList extends [Activity](https://www.mindstick.com/forum/12894/how-to-force-recreation-of-activity-fragment-on-restore) {

CheckBox cb1, cb2, cb3, cb4;

[Boolean](https://www.mindstick.com/forum/160332/how-does-the-boolean-function-work) checked = false;

@Override

protected void onCreate([Bundle](https://www.mindstick.com/interview/2401/what-is-app-bundle) savedInstanceState) {

setContentView(R.layout.activity_tasks);

super.onCreate(savedInstanceState);

findID();

cb1 = (CheckBox) findViewById(R.id.checkBox1);

boolean isChecked = getBooleanFromPreferences("isChecked");

Log.i("start", "" + isChecked);

cb1.setChecked(isChecked);

cb1.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override

public void onCheckedChanged(CompoundButton view, boolean isChecked) {

Log.i("boolean", "" + isChecked);

putBooleanInPreferences(isChecked,"isChecked");

}

});

}

public void putBooleanInPreferences(boolean isChecked, [String](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) key) {

SharedPreferences sharedPreferences = this

.getPreferences(Activity.MODE_PRIVATE);

SharedPreferences.[Editor](https://www.mindstick.com/forum/78/how-avoid-the-html-tag-and-remove-the-formating-of-copy-in-ajax-editor) editor = sharedPreferences.edit();

editor.putBoolean(key, isChecked);

editor.commit();

}

[private](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) boolean getBooleanFromPreferences(String key) {

SharedPreferences sharedPreferences = this

.getPreferences(Activity.MODE_PRIVATE);

Boolean isChecked = sharedPreferences.getBoolean(key, false);

return isChecked;

}

private void findID() {

cb1 = (CheckBox) findViewById(R.id.checkBox1);

cb2 = (CheckBox) findViewById(R.id.checkBox2);

cb3 = (CheckBox) findViewById(R.id.checkBox3);

cb4 = (CheckBox) findViewById(R.id.checkBox4);

}

}

## Replies

### Reply by Anonymous User

You need to update the value in SharedPreferencesevery time CheckBox check status is changed. Remove comment from this line Settings.this.putBooleanInPreferences(isChecked,"isChecked") in setOnCheckedChangeListener.\
So, your listener will be as below :\

cb1.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override

public void onCheckedChanged(CompoundButton view, boolean isChecked) {

Log.i("boolean", "" + isChecked);

putBooleanInPreferences(isChecked,"isChecked");

}

});

Hope this helps.\


---

Original Source: https://www.mindstick.com/forum/2420/checkbox-status-is-not-saving-in-android

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
