Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to use <code>Intents</code> to "switch windows". A "window" is called an <code>Activity</code> in Android and you set the visual content of an <code>Activity</code> using the <code>setContentView()</code> method in the <code>onCreate()</code> call of the <code>Activity</code>.</p> <p>To launch another <code>Activity</code> from your current <code>Activity</code>, simply create an <code>Intent</code> with a few parameters and call <code>startActivity()</code> with that <code>Intent</code>. Here's an example:</p> <pre><code>Intent i = new Intent(this, TheNextActivity.class); startActivity(i); </code></pre> <p>Don't forget to include your second <code>Activity</code> in the Android manifest file. All <code>Activities</code> in your application must be included in that file.</p> <p>Other things to note is that you don't really use <code>System.exit()</code> in Android. Just call <code>finish()</code>. It's advised to let Android manage applications and its resources rather than doing it yourself, but if you want to make sure that your application really is shut down, feel free to use <code>System.exit()</code> anyway. There's also no need for overriding <code>onBackPressed()</code> if you're only calling <code>finish()</code>. That's standard behaviour in Android when you hit the back button.</p> <p>Also, you don't call <code>setContentView()</code> more than once per <code>Activity</code>. You start a new <code>Activity</code> when you need to change the visuals (or use one of the specialized Widgets to switch between layouts.</p> <p>This also explains why you're experiencing your "problem". You may have changed the layout of the <code>Activity</code> using <code>setContentView()</code>, but there's still only one <code>Activity</code> running - when you call <code>finish()</code>, that <code>Activity</code> gets closed. If you had started a second <code>Activity</code> with a different layout, like you're supposed to do, Android would have closed that second <code>Activity</code> and would have returned you to the first.</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