我在添加Facebook身份验证时遇到问题,因为我也在使用Google身份验证,这就是为什么我会出错

         public class SignUpActivity extends AppCompatActivity {
                callbackManager.onActivityResult(requestCode, resultCode, data);
                super.onActivityResult(requestCode, resultCode, data);
            //Google
            @Override
            public void onActivityResult(int requestCode, int resultCode, Intent data) {
                super.onActivityResult(requestCode, resultCode, data);

                // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
                if (requestCode == RC_SIGN_IN) {
                    Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
                    try {
                        // Google Sign In was successful, authenticate with Firebase
                        GoogleSignInAccount account = task.getResult(ApiException.class);
                        firebaseAuthWithGoogle(account);
                    } catch (ApiException e) {
                        // Google Sign In failed, update UI appropriately
                        Log.w(TAG, "Google sign in failed", e);
                        // ...
                    }
                }
            }

            //and Facebook
            @Override
            protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            callbackManager.onActivityResult(requestCode, resultCode, data);
            super.onActivityResult(requestCode, resultCode, data);
    }


您如何看到我有两个onActivityResult方法。有什么方法可以连接它们并消除错误?
这是我的错误的样子


方法onActivityResult(int,int,Intent)已在类中定义
注册活动


这只是现有两种相同方法的交流。
谢谢。

最佳答案

onActivityResult是一种Android方法,它从您以startActivityForResult开始的活动中接收结果,并返回您提供的request_code int。

解决方案是在startActivityForResult处使用不同的REQUEST_CODES,因此可以在onActivityResult中进行比较

喜欢:

private static final int FACEBOOK_REQUEST_CODE = 1;
private static final int GOOGLE_REQUEST_CODE = 0;

startActivityForResult(googleLoginIntent, GOOGLE_REQUEST_CODE)
startActivityForResult(facebookLoginIntent, FACEBOOK_REQUEST_CODE)

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == GOOGLE_REQUEST_CODE) {
        //do the code for google result
    } else if (requestCode == FACEBOOK_REQUEST_CODE) {
        // do the code for facebook result
    }
}

关于java - 如何连接2 onActivityResult?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60972295/

10-12 04:48