All activities in my apps having Logout button and user can Logout from any activity. I want to send user to Login Activity without showing previous activity. for this i am using:
Following is the logout method delete session
public void logoutUser() {
//clearing all data from sharedPreferences
editor.clear();
editor.commit();
Intent intnt = new Intent(contxt, LoginActivity.class);
// Closing all the Activities
intnt.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// Add new Flag to start new Activity
intnt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
// Staring Login Activity
contxt.startActivity(intnt);
}
from Second activity when user click on logout button then Logout method call. My Second activity class extends SherlockFragmentActivity.
public void Logout(MenuItem v) {
sessionMngr.logoutUser();
}
I get to the login screen when I press the logout button, but when I press back button on the device it is showing the previous activities - I should go to the Android home screen when I press back button in the login screen.
I've seen some question on stackoverflow but not achieve my goal. somebody said me use android:noHistory="true" in manifest file but what happen when i am in Third activity and press back the button it is showing android home screen but it should go to second activity. I also tried FLAG_ACTIVITY_NO_HISTORY but this does not accomplish my goal either.
I don't Understand where I am wrong. Please does anyone have solution.
Thanks in advance