简体   繁体   中英

Facebook Login in Android pops up two login screen

I have integrated Facebook login to my android app. but whenever I click on the "continue with Facebook", it pops up two login screens ie when I enter credential and continue, instead of returning to the app there will still one more login screen. if just cancel it, it will return to the app and logs in.

My question is how to remove the extra login screen, I think the reason for this problem is facebook SDK widget automatically launching the login screen.

public void onClick(View view) {

   if(view.getId() == R.id.fb_login_button){
        ParseFacebookUtils.logInWithReadPermissionsInBackground(MainActivity.this, mPermissions, new LogInCallback() {
            @Override
            public void done(ParseUser user, ParseException e) {
                if (user == null) {
                    Log.d("Login", "Uh oh. The user cancelled the Facebook login.");
                    Toast.makeText(getApplicationContext(),"An Error occurred, Try Again!",Toast.LENGTH_LONG).show();
                } else if (user.isNew()) {
                    Log.d("Login", "User signed up and logged in through Facebook!");
                   getUserDetailsFromFB();
                } else {
                    Log.d("Login", "User logged in through Facebook!");
                   getUserDetailsFromParse();
                    showHomeActivity();
                }

            }
        });
    }
    }

Activity.xml

<com.facebook.login.widget.LoginButton
        android:id="@+id/fb_login_button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:paddingTop="12dp"
        android:paddingBottom="12dp"
        android:onClick="onClick"
        />

Try this :- on one click view.setEnabled(false); and enable again in done like view.setEnabled(true); Use this code..

public void onClick(View view) {

    view.setEnabled(false); //disable the button click

    if(view.getId() == R.id.fb_login_button){


        ParseFacebookUtils
       .logInWithReadPermissionsInBackground(MainActivity.this, mPermissions, new LogInCallback() {
        @Override
        public void done(ParseUser user, ParseException e) {

            view.setEnabled(true); // enable it again.. 
            if (user == null) {
                Log.d("Login", "Uh oh. The user cancelled the Facebook login.");
                Toast.makeText(getApplicationContext(),"An Error occurred, Try Again!",Toast.LENGTH_LONG).show();
            } else if (user.isNew()) {
                Log.d("Login", "User signed up and logged in through Facebook!");
               getUserDetailsFromFB();
            } else {
                Log.d("Login", "User logged in through Facebook!");
               getUserDetailsFromParse();
                showHomeActivity();
            }

        }
    });
}
}

This happens because you are clicking the button twice..

So, after clicking disable the button and then again in done enable it again !

In future if anyone comes across this problem.

I couldn't figure out the solution to this problem. However i found way around it by removing facebook login widget and added custom fb login button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM