I create one application and never use finish() for each activity. If my user clicks on the logout button it goes to the previous page.
How can I close my previous
Intent intent = new Intent(this, LoginActivity.class);
ComponentName cn = intent.getComponent();
Intent mainIntent = IntentCompat.makeRestartActivityTask(cn);
startActivity(mainIntent);
Description:
public static Intent makeRestartActivityTask (ComponentName mainActivity)
Make an Intent that can be used to re-launch an application's task in its base state. This is like makeMainActivity(ComponentName), but also sets the flags FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TASK.