Note that there are some explanatory texts on larger screens.

plurals
  1. POThe app doesnt remember shared preferences values
    primarykey
    data
    text
    <p>I am working on an Android app and the app is seperated into two lets say for men and women. The user chooses which part of activity it wants to oen. For example, if the user a man, he chooses man part, if she a woman, she clicks woman button and the page for women appears.</p> <p>To avoid bothering users, I put a check box and I said remember my choise next time. Very common thing...</p> <p>I tried to use shared preferences for this, but it doesnt work. It asks the question every time the app open. Here are the codes:</p> <p><strong>The Activity I ask the question</strong></p> <pre><code>View checkBoxView = View.inflate(this, R.layout.activity_menu, null); CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkbox); checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked){ SharedPreferences.Editor prefEditor = getPreferences(MODE_PRIVATE).edit(); prefEditor.putString("Remember", "Checked"); prefEditor.commit(); } } }); </code></pre> <p><strong>The splash activity which decides to ask question or to open the chosen activty before</strong></p> <pre><code>SharedPreferences sp = getPreferences(MODE_PRIVATE); String str1 = sp.getString("Remember", ""); String str2 = sp.getString("Hacc", ""); if (str1 == "") { Intent menuIntent = new Intent( "com.uygulama.hacc.MenuActivity"); startActivity(menuIntent); } else{ if(str2 == "Hacc" ){ Intent mainIntent = new Intent( "com.uygulama.hacc.HaccActivity"); startActivity(mainIntent); } else{ Intent mainIntent = new Intent( "com.uygulama.hacc.UmreActivity"); startActivity(mainIntent); } } </code></pre> <p>I am new on Android so, any help would be appreciated. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload