Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6078845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:52:45+00:00 2026-05-23T10:52:45+00:00

How to keep checkbox state and settings for camera after the destruction of activity?

  • 0

How to keep checkbox state and settings for camera after the destruction of activity?

Or in other words, how to persist the camera parameters into SharedPreferences?

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu_old);
SharedPreferences preferences = 
getSharedPreferences("PREFS_NAME",MODE_WORLD_READABLE);

yourCheckBox = (CheckBox) findViewById( R.id.fonarb );
yourCheckBox.setChecked(preferences.getBoolean("lol",false));
yourCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener()

{
@Override
public void onCheckedChanged(CompoundButton   yourCheckBox,
        boolean isChecked) {
     if (isChecked){

         Parameters params = camera.getParameters();
         params.setColorEffect(Parameters.EFFECT_NEGATIVE);
         camera.setParameters(params);


     }
     else {     
         Parameters params = camera.getParameters();
         params.setColorEffect(Parameters.EFFECT_NONE);
         camera.setParameters(params);

     }

}


});

public void onStop(){
 SharedPreferences settings = getSharedPreferences("PREFS_NAME", MODE_WORLD_READABLE);
 SharedPreferences.Editor editor = settings.edit();
 editor.putBoolean("lol", true);


 editor.commit();
 super.onStop();
}

Did as you said, does not want to save settings! : (

    SharedPreferences preferences = getSharedPreferences("qwe",MODE_PRIVATE);
    yourCheckBox = (CheckBox) findViewById( R.id.fonarb );
    yourCheckBox.setChecked(preferences.getBoolean("lol",false));
    yourCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener()

    {
    @Override
    public void onCheckedChanged(CompoundButton   yourCheckBox,
            boolean isChecked) {
         if (isChecked){

             Parameters params = camera.getParameters();
             params.setColorEffect(Parameters.EFFECT_NEGATIVE);
             camera.setParameters(params);



         }
         else {     
             Parameters params = camera.getParameters();
             params.setColorEffect(Parameters.EFFECT_NONE);
             camera.setParameters(params);

         }

    }


    });









    protected void onPause()

   {
        SharedPreferences settings = getSharedPreferences("qwe",MODE_PRIVATE);
    SharedPreferences.Editor editor = settings.edit();
    yourCheckBox = (CheckBox) findViewById( R.id.fonarb );
    editor.putBoolean("lol", yourCheckBox.isChecked());
    editor.commit();
        super.onPause();
     }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:52:46+00:00Added an answer on May 23, 2026 at 10:52 am

    Instead of always storing “true” in the SharedPreferences, simply store the current state of the CheckBox.

    SharedPreferences settings = getSharedPreferences("PREFS_NAME", MODE_WORLD_READABLE);
    SharedPreferences.Editor editor = settings.edit();
    CheckBox yourCheckBox = (CheckBox) findViewById( R.id.fonarb );
    editor.putBoolean("lol", yourCheckBox.isChecked());
    editor.commit();
    

    You also might consider moving this code to onPause() instead of onStop(). The operating system (pre-Honeycomb) can kill your activity once it has been paused without ever calling onStop(). If that happens, your SharedPreferences will not be saved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Keep getting this error after inserting a subdatasheet into a query and trying to
Keep running into When using the multi-mapping APIs ensure you set the splitOn param
I have the code below, now I need to keep track of the checkbox
All I am trying to do is to change the state of checkbox on
My problem is I want to keep rotating the scene if the checkbox is
Does anyone know how to make an uneditable checkbox ina QTreeWidgetItem but keep the
I have checkbox in preferences. I want to keep screen on if checkbox is
I have some checkbox that looks like this <%= Html.CheckBox(Remember) %> <%= Html.Label(Remember, Keep
I keep getting stuck on this one little thing. I append a checkbox and
How can I keep checkboxes selected after the form has been submitted? I found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.