Android : After Callback from Facebook, Which State will called of my Main Activity?
i am using Facebook sdk in my android project and in my main activity there is a button for Login clicking on that button will make user login to Facebook and the callback return to the Main Activity.
All works Fine.
Now i want when the callback is done, i need to change the Text of that Button from Login to Logout.. how can i do that?
what state will be called of my main activity on call back.. i mean onResume() or onRestart() or what ??
please help me doing this.. and make me understand how can it be possible...
i have read enough documentations and tutorial for Android lifecyle..but still i couldn't find anyway to 开发者_高级运维do this.
Thank You, Mayur Parekh
So I'm assuming you login into facebook by doing something like this:
mFacebook.authorize(this, null, requestCode, new Facebook.DialogListener() {
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
}
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
}
public void onCancel() {
// TODO Auto-generated method stub
}
});
If authentication was succesfull the onComplete()
method will be called on your DialogListener
. Also on your Activity
I suppose that the onResume()
method is called but this will be called when the FacebookDialog
is dismissed, no matter what the login was sucesfull or not.
SessionEvents.AuthListener listener = new SessionEvents.AuthListener() {
public void onAuthSucceed() {
changeText("Facebook Logout");
}
public void onAuthFail(String error) {
Log.i("Login Failed", "Try Again");
}
};
SessionEvents.addAuthListener(listener);
facebookConnector.login();
This is what i have done in my main activity inside the button click event this will call the Facebook Dialog for log in and if after that login is success full will do the task same for login fail.
I am using default FACEBOOK SDK in my project.
精彩评论