I have two activities, say LoginActivity which contains a login UI and HomeActivity. On HomeActivity, I have put a button that calls the method below:
public void goToLoginPage(View view) {
finish();
super.finish();
Intent i = new Intent(HomePageActivity.this, LoginActivity.class);
startActivity(i);
}
But when I click this button, the login page with the last entered credentials appears once again. Instead I want a fresh login page or at least without last entered credentials.
Based on your information, LoginActivty is the starting activity and that activity, after a successful login, starts the HomePageActivity. To return to the LoginActivity, you can execute the following:
This will only work if, when LoginActivity launched HomePageActivity, it did not call finish() on itself (ie: the instance of LoginActivity must still be present in the activity stack). Also, the launchMode of LoginActivity must be either default (ie: not specified at all) or “standard”.
This will result in the current instance of LoginActivity being finished and a new instance of LoginActivity will be created and the onCreate() method will be called.