Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you can do like this <strong>onclick of back button.</strong></p> <pre><code>@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { finish();// call finish() on click of back button } return super.onKeyDown(keyCode, event); } </code></pre> <p><strong>for example :</strong> When you <strong>moving from A activity to B activity</strong> using startActivity(new intent(...)); <strong>don't finish or kill A activity, It ll be in stack</strong>.<code>So when you click on back button in B activity you can go back to A activity, which is already in stack.</code></p> <p><strong>when you want to go back to main menu call finish() on every activity when your moving to next activity</strong>.</p> <p><strong>for example :</strong> When you <strong>moving from A activity to B activity</strong> using startActivity(new intent(...)); call <code>finish()</code> to kill A activity.<code>So when you click on back button in B activity you can go back to Main Menu coz every activity ll be killed.</code></p> <p>snippet is here :</p> <pre><code>startActivity(new intent(A.this, B.class)); finish(); // when you click back button on B activity, directly you can go to main menu </code></pre> <p><strong>Updated :</strong> Other way to kill the app using below code on back button pressed. <strong>But not recommended</strong></p> <pre><code> @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { android.os.Process.killProcess(android.os.Process.myPid());// Kill the app on click of back button. } return super.onKeyDown(keyCode, event); } </code></pre> <p>hope this might help you to understand the concept.</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. This table or related slice is empty.
    1. 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