Note that there are some explanatory texts on larger screens.

plurals
  1. POAvoiding showing Previous Activities by overriding device back button
    primarykey
    data
    text
    <p>I havean Activity_A which has a Log-out option. On clicking that I call the Log-in Activity. So when i Click device back button when i am on Login-in Activity it takes me back to the Activity_A where i have the log-out option. what i wanted is, when i click device back button when i am on log-in Activity it must take me to the device home screen. something like "close application" or "clear activity stack".</p> <p>I tried this:</p> <pre><code>Intent intent = new Intent(Activity_A.this, LoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); </code></pre> <p>but it didn't work, i also tried using finish() int the above code, then it takes me to the Activity i called before Activity_A (as expected).</p> <p>I searched for my case, and could not find a perfect solution, can someone please help me achieve what i wanted?</p> <p>and i have an idea of overriding device back button onClick in my login Activity so that it shows the home screen of the device and clears all the activity stack....is it possible? if yes, is it safe?</p> <p>This is what i have done in LoginActivity, which works just like i wanted</p> <pre><code>public void onBackPressed() { // TODO Auto-generated method stub super.onBackPressed(); Intent startMain = new Intent(Intent.ACTION_MAIN); startMain.addCategory(Intent.CATEGORY_HOME); startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(startMain); } </code></pre> <p>But is there any other way to achieve this without overriding onBackPressed()??</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.
 

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