Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a short/alternate version assuming a view (view1) of some sort.</p> <pre><code>import android.os.Bundle; import android.app.Activity; import android.graphics.Color; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { private static final int DEFAULT_COLOR = Color.WHITE; private int myColor; // Assuming a 'view' of some sort private View myView; // Declare UI elements private Button firstButton; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Our only layout for this app // is main.xml myView = (View) findViewById( R.id.view1 ); firstButton = (Button) findViewById( R.id.button1 ); Log.i("MainActivity", "onCreate" + ((null == savedInstanceState) ? "(null)" : "(savedInstanceState)")); if (savedInstanceState != null) { myColor = savedInstanceState.getInt("COLOR"); } else { myColor = DEFAULT_COLOR; } myView.setBackgroundColor(myColor); firstButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (myColor == Color.WHITE) myColor = Color.BLACK; else if (myColor == Color.BLACK) myColor = Color.WHITE; myView.setBackgroundColor(myColor); } }); } @Override // this method is called before android trashes and recreates your activity protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("COLOR", myColor); } } </code></pre> <p>Alternatively you could do it the cheap-dumb-ass way: Locking the screen. add the 'android:configChanges' attribute to your activity.</p> <pre><code> &lt;activity android:name="UserIdActivity" android:label="@string/app_name" android:configChanges="orientation" /&gt; </code></pre> <p>And implement the 'onConfigurationChanged' callback to do nothing</p> <pre><code>public void onConfigurationChanged ( Configuration newConfig) { } </code></pre>
    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. 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.
    3. 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