简体   繁体   中英

onActivityResult to handle both facebook and twitter login

In facebook, Im asked to do:

 protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
}

In Twitter, Im asked to do:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Pass the activity result to the login button.
    loginButton.onActivityResult(requestCode, resultCode, data);
}

How to combine them, and what is onActivityResult used for? To tell button text to change to ":logout"?

What you can do is Identify onActivityResult on requestCode

See this link for Twitter Request code

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == TwitterAuthConfig.DEFAULT_AUTH_REQUEST_CODE){
        //  twitter related handling
    }else{
       // facebook related handling
    }
}

No, this is the method called after executing an Intent which your app would call. For example, a facebook login is initiated by your app, this method gets called for whatever happened to the facebook login (Failed, Cancelled etc.). When executing an intent you get to pass a Request Code to the Intent parameters the same request code is then passed to this onActivityResult method. You can use this request code to determine which results are the intent data received from (whether from facebook or twitter or others.

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