In Activity login, right after the line you have startActivity()
place finish();
. This will close the Activity login by making sure that clicking the back does not return to it and the application is closed.
Anything like that:
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
finish();
The same can be achieved by Intent flags:
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
However, since there is only one Activity in the Stack, it is best to use the first method.
Your question is very bad, and there are several examples out there, it is better to do a survey before asking.
– Wallace Roberto
I can also suggest you to change the logic, like, Open Activity(Splashscreen)-> Checklogin (check if you are logged in)-> Main Menu, if not-> Login activity , and a reading on activity lifecycle.
– Wallace Roberto