Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Save History When Launch Second Activty
    primarykey
    data
    text
    <p>Created 2 activity with same layout, same button placement, same button id, everything is the same</p> <p>Example:</p> <p>Added 3 Buttons in first_activity and second_activity, everything placed on the same place, and with same id, button1, and button2 but the last button, "check" set visibility to gone.</p> <p><strong>FIRST ACTIVITY</strong></p> <p>Set Background Resource for button1 and button2</p> <pre><code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.first_activity); .................................................. //Change button1 drawable to example1.png button1 = (Button) .... button1.setBackgroundResource(R.drawable.example1); //Change button2 drawable to example1.png button2 = (Button) .... button2.setBackgroundResource(R.drawable.example1); //Check Button check = (Button) findViewById(R.id.check); check.setBackgroundResource(R.drawable.example1); .................................................. } </code></pre> <p>button1 onClick</p> <pre><code>public void button1_click (View v){ //If button2 drawable same as check it will changed to another drawable if (button2.getBackground().getConstantState().equals(check.getBackground().getConstantState())){ button2.setBackgroundResource(R.drawable.example2); } else { button2.setBackgroundResource(R.drawable.example1); } } </code></pre> <p>button2 onClick</p> <pre><code>public void button2_click (View v){ Intent second_activity=new Intent (getApplicationContext(), second_activity.class); startActivity(second_activity); //Calling Second Activity when button2 pressed finish(); //Finish First Activity } </code></pre> <p><strong>CONDITION :</strong> First pressed button1, button2 drawable changed to example2.png. Second Pressed button2 that will launch second_activity and close first_activity</p> <p><strong>MY QUESTION :</strong> How to keep button2 drawable set to example2.png after launch second_activity</p> <p>I'm using code below in second_activity the same as first_activity</p> <p><strong>SECOND ACTIVITY</strong></p> <pre><code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second_activity); .................................................. //Change button1 drawable to example1.png button1 = (Button) .... button1.setBackgroundResource(R.drawable.example1); //Change button2 drawable to example1.png button2 = (Button) .... button2.setBackgroundResource(R.drawable.example1); //Check Button check = (Button) findViewById(R.id.check); check.setBackgroundResource(R.drawable.example1); .................................................. } </code></pre>
    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.
 

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