Do not allow onBackPressed to run

0

In my application, when the user logs in if he presses onBackPressed() on his smartphone the application should not go back to the previous screen. When it logs in and I change activity I set it to Intent the following code:

    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

In some cell phones the following code works .. In others it does not. What to do?

    
asked by anonymous 21.10.2015 / 20:05

1 answer

2

In order to prevent onBackPressed() doing something in some Activity just overwrite it in Activity in question:

@Override
public void onBackPressed() {
    // Não faz nada
}

But in your case, I think it would be ideal to end the Activity login by calling finish() soon after startActivity() that starts the second activity:

startActivity(new Intent(this, SegundaActivity.class));
finish();

So the login activity exits the activities stack and gets the second activity at the top.

    
21.10.2015 / 20:14