I think that because of the package manager, activity starts with a new history stack.
Try using the activity name instead of getting it from the package manager. For instance.
Intent i = new Intent(getApplicationContext(), LoginActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
source
share