So I’m in activity Home which has:
setContentView(R.layout.home);
Now, from Home activity, one can go to Settings activity which has:
setContentView(R.layout.settings);
It has a couple of CheckBoxes and EditTexts.
Is it possible to edit the state of those checkboxes from the Home activity?
I already declared them in Home like this:
CheckBox checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
Which finds the ID just fine but the application crashes on the line where I try to
checkBox1.setChecked(true);
Is it not possible to access it from another activity??
Thank you
In general, an activity cannot directly modify view elements of another activity, since Android makes no guarantees regarding the lifecycle of each activity. Activity A may invoke Activity B, but if memory is running low while B is displayed, A may be destroyed.
You will need to use intents to pass data from one activity to another.