开发者

Login activity problem

开发者 https://www.devze.com 2023-04-08 14:29 出处:网络
Im currently developing an a开发者_如何学编程pplication for android, the first screen of the application is the LoginActivity, it is authenticating with facebook and a facebook login dialog is shown o

Im currently developing an a开发者_如何学编程pplication for android, the first screen of the application is the LoginActivity, it is authenticating with facebook and a facebook login dialog is shown on users request. The whole login process is working great, when you have logged in user are brought to a new activity. I've created a logout function in that activity which logging the user out of facebook in the whole application, but. If you press the "back-button" on an android device when the user is at the activity where you are when you have logged in the loginactivity is shown for the user. I want to make it impossible for the user to show the loginactivity but i don't know how. When the user successfully logging in from the beggining the following lines are runned:

        Intent intent = new Intent().setClass(LoginActivity.this, LocationActivity.class);
        startActivity(intent);

And when the user successfully logged out from the MainActivity the following lines are runed:

ApplicationController appController = (ApplicationController)getApplicationContext();
            appController.setfullnametoNull();
            appController.setuseridtoNull();
            finish();

Any suggestions on how to make it impossible for the user to get to the loginactivity when the user is currently logged in?


finish() the activity and if the user navigates to other app without log out then you should check in the login activity when comes back to app and redirect the user to appropriate activity. You need to save the login credentials for this. You can use SharedPreferences for this.


Use an broadcast intent which you send from the activity you start after the login activity. Then use the login activity as the receiver of the broadcast intent. Then you can use this broadcast to call finish() for the login activity. This way the login activity should get out of the android activity stack.


Not sure if I understood your question correctly... you are saying after you logged in and another Activity is started the user hits the back button and the activity is shown again?

If yes: you can prevent this with starting the activity using startActivityForResult(intent, REQUEST_CODE) instead of using startActivity(intent).

Then you have to add this method:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE) {
        finish();
    }
}
0

精彩评论

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

关注公众号