Adam Szymański :
I have problem with adding a Facebook Authentication because I'm using Google Authentication too and this is why I have error
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);
}
How you can see I have two onActivityResult methods. Is there any way to connect them and get rid of an error ? This is how looks like my error
method onActivityResult(int,int,Intent) is already defined in class SignUpActivity
It's just a communicate of existing two the same methods. Thanks.
Marcos Vasconcelos :
onActivityResult
is a Android method, it receives results from activities you started with startActivityForResult
and returns the request_code int you provided.
The solution is to use different REQUEST_CODES at startActivityForResult
, so you can compare then in onActivityResult
like:
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
}
}
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=385078&siteId=1