I'm very new to Java and I'm attempting to write an android app and going through the facebook api. I'm looking at this page, specifically, this
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
}
@Override
public void onCancel() {
// App code
}
@Override
public void onError(FacebookException exception) {
// App code
}
});
This work just fine, I'm just trying to understand how. I'm not understanding the method in a method and more specifically, how would I extract this if I wanted to write it differently?
I tried creating another class
public class FaceBookCallbackLogin implements FacebookCallback<LoginResult> {
@Override
public void onSuccess(LoginResult loginResult) {
....
}
@Override
public void onCancel() {
}
and tried to initiate the login from my MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_main);
info = (TextView)findViewById(R.id.info);
loginButton = (LoginButton)findViewById(R.id.login_button);
loginButton.setReadPermissions("email");
loginButton.registerCallback(callbackManager, new FaceBookCallbackLogin());
}
but, this never calls the onSuccess method in FaceBookCallbackLogin, and I can't call it explicitly because I don't have the param LoginResult.
So, how would i write this so I can have the login in a different class? In the original code, where is the param for onSuccess - LoginResult - coming from?