0
//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 am unable 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 whenever the user enters the Mainactivity screen, save the status that was sent from the preferences Activity.
I can already pass the status of the checkbox. So I received it correctly in the other Activity. Now I need to SAVE and (update) the status of the same.
– user9063977
For whenever the user enters the Mainactivity screen, stay saved the status that was sent from the preferences Activity. Got it?
– user9063977
Is emitting some error when you try to save in preferences?
– Guilherme Montanher
Actually, no. But when I have the code to save and restart the app, Toast does not appear. Got it? Being that he was supposed to have saved the String and have come back to find out if it contains "checked_thumb" in the same.
– user9063977
Thus, successively appeared the Toast, if had saved the String and ascertained.
– user9063977
In the preferences activity everything is ok! I no longer need to save there. I want to save in Mainactivity. The activity that was received to String.
– user9063977