I have searched a lot for this ,but nothing gave a solution. I will explain you the scenario: my application is with login page -> User verification page-> Home page (Home page with multiple menus and a footer -Horizontal scroll view). Application login only happens for the first time or when user logout.On successful login ,user is navigated to the authentication page and login activity is finished .My code is
Intent loginIntent = new Intent(Login.this,UserAu.class);
loginIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
loginIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(loginIntent);
finish();
On successful authentication, user is navigated to application home page and again the authentication activity is finished.
Intent proceedIntent = new Intent(UserAu.this,Home.class);
proceedIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
proceedIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(proceedIntent);
finish();
Now the user is in Home page and he clicked Menu 1 resulting in Activity A then to Activity B from A. These activities are not finished .Logout button is in footer (which is a class extending a Linear layout )and when user logout ,the current activity is finished and navigated to login screen using
Intent loginscreen=new Intent(context,Login.class);
loginscreen.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
loginscreen.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(loginscreen);
((Activity) context).finish();
My issue occurs when user press back button from Login page ,its navigating to Activity A . I tried this on Login class
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
moveTaskToBack(true);
return true;
}
}
But now when the user takes the application again its navigating to Home page.Again if user press back button, Application is closed and only loads the Login page afterwards. I searched for a solution but no results. Please give me a solution.Thanks in advance.