Prevent the back button in the login activity

android, android-activity

Solution

You can call `finish();` just after `startActivity()`. This will kill MainActivity so the back button will close the app.

Problem

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); ```

Original source

Related problems