I am working on a login screen for my application. If I open the application, by either running from eclipse or by selecting the application icon installed on the emulator, it will run an AuthUser.class which checks for a valid token on a remote server. If the user is not logged in then the AuthUser.class forwards to Login.class via…
if (authtoken.length() == 0 || authtoken.length() > 0
&& checkAuthToken(authtoken) == false) {
Intent intent = new Intent();
intent.setClass(AuthUser.this, Login.class);
startActivity(intent);
finish();
}
This works great, as when I use the back button on the emulator it will close the app rather than go back to the login screen. Perfect.
Now when I am coming from a share menu, like when I select share icon on an image within the gallery, and then select my application from the popup menu I also forward to the Login.class via…
Intent intent1 = new Intent();
intent1.setClass(SharePictureMenu.this, AuthUser.class);
startActivity(intent1);
finish();
Now when I login from here and it forwards to AuthUser.class as per usual, however, the back button press now takes me back to the login screen, even though I am forwarding and finishing exactly the same in both cases. Obviously I don’t want that behavior as I want it to close the app and return to the gallery after login so the user can continue to share images immediately without having to go back through the login screen.
Any suggestions, hacks or otherwise on fixing this would be greatly appreciated.
If you are calling finish() on that activity, before that functions return it will be marked as finished by the activity manager and the user can not return to it. I don’t know of a way this could not happen. Make sure you are actually finishing that activity, and that you are not doing something like starting it twice.
Some useful tools for debugging: