I am working on an Android app.
There is a web admin panel where I can forced an app user to logout from the app. That feature is working fine. The current app user is forced to logout and gets a Toast message reporting him that the administrator has canceled his account. The login screen activity is shown.
My issue is that I want to terminate the activity that is getting the order to force the logout, but with my current code the activity is not terminated. The login screen is shown but in the background the first activity is running, then it shows the Toast again and again.
This the current code for the logout function:
private void logoutUser() {
SharedPreferences prefs2 =
getSharedPreferences(MISDATOS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor2 = prefs2.edit();
editor2.putString("LOGEADO", "NO");
editor2.apply();
// Launching the login activity
Intent intent = new Intent(this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
this.finish(); // Call once you redirect to another activity
}