// I can send and receive two different values in one
@Override
public void onBackPressed() {
if(checkBox.isChecked())
{
String trueThumb_check = "checked_thumb";
Intent i = new Intent(getBaseContext(), MainActivity.class);
i.putExtra("trueThumbnail", trueThumb_check);
startActivity(i);
killAc();
}
else
{
Intent i = new Intent(getBaseContext(), MainActivity.class);
i.putExtra("falseThumbnail", "");
startActivity(i);
killAc();
}
}
// Then I received different values:
try {
Intent thumb_check = getIntent();
String thumb_thumb = thumb_check.getStringExtra("trueThumbnail");
if (thumb_thumb.contains("checked_thumb")){
Toast.makeText(MainActivity.this, "checkBox ativo", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "not checkBox", Toast.LENGTH_SHORT).show();
}
} catch (Throwable e) {
e.printStackTrace();
}
// But I'm not able to save the result. It needs to be saved and updated when the checkBox is checked or not
SharedPreferences sharedPref = getSharedPreferences("ch4an.ytheloader", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("trueThumbnail", thumb_thumb);
editor.commit();
EDIT: For every time the user enters the MainActivity screen, the status that was sent from the preferences activity is saved.