开发者

Back button issues after forwarding intents via share menu

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:

  • The output of "adb logcat" will contain a log for every activity that is started.
  • The output of "adb logcat -b events" will contain a log for every activity that is finished, with the reason why it was finished (and various other activity operations). You can combine this with the other with "adb logcat -b events -b system".
  • "adb shell dumpsys activity" will give you the current activity stacks, so you can see the current activities being managed for your app and how they are related to others.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜