I have an activity named MainActivity and another called LoginActivity. The main activity cannot be visible to logged out users. In the onCreate method of MainAcitivity I verifiy if the user is logged out and then I create the LoginActivity.
The problem is that if the user press the back button of the cellphone, the app go back to the MainActivity.
How I prevent this?
The code of the LoginAcitivity creation is this:
Intent i = new Intent(_context, LoginActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
_context.startActivity(i);
You can call finish(); just after startActivity(). This will kill MainActivity so the back button will close the app.
after: _context.startActivity(i);
put: finish();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With