Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can add an "extra" to the Intent that you use to start the second activity. This "extra" could contain information about the state of the buttons. In the <code>onCreate()</code> of the second activity, you can examine the information in the "extra" and set the backgrounds of the buttons accordingly.</p> <p><strong>EDIT: Add example code</strong></p> <p>I would create a boolean variable for each button, indicating the state of the background and add this to each activity, like this:</p> <pre><code>private boolean button1Checked; private boolean button2Checked; </code></pre> <p>Then, whenever you change the background color, you change the state of the appropriate variable:</p> <pre><code>if (...) { button2.setBackgroundResource(...); button2Checked = true; // or false, whatever } </code></pre> <p>Then, when you want to start activity2, you add the state of the 2 buttons as extras to the Intent, like this:</p> <pre><code>Intent intent=new Intent (this, second_activity.class); // use "this" instead of getApplicationContext() intent.putExtra("button1Checked", button1Checked); intent.putExtra("button1Checked", button2Checked); startActivity(intent); </code></pre> <p>Now, in <code>onCreate()</code> of the second activity, you recover the state of the buttons from the passed extras, like this:</p> <pre><code>button1 = (Button) .... button1Checked = getIntent().getBooleanExtra("button1Checked", false); if (button1Checked) { button1.setBackgroundResource(...); // true state } else { button1.setBackgroundResource(...); // false state } button2 = (Button) .... button2Checked = getIntent().getBooleanExtra("button2Checked", false); if (button2Checked) { button2.setBackgroundResource(...); // true state } else { button2.setBackgroundResource(...); // false state } </code></pre> <p>Hopefully you get the idea.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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