• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Wait until callback of request is completed, Facebook-SDK android

I have the following class that I instantiate from my fragment:
Java:
public class FacebookLogin {
    private CallbackManager mCallbackManager;
    private LoginButton lButton;
    private AccessToken accessToken;
    private Profile profile;
    private static final String TAG = "FacbookLogin";

   public FacebookLogin(Context c) {
        FacebookSdk.sdkInitialize(c);
        mCallbackManager = CallbackManager.Factory.create();
        Log.i(TAG, " Constructor called");
    }

    private FacebookCallback<LoginResult> mCallback = new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {

            Log.i(TAG, " logged in...");

            AccessToken accessToken = loginResult.getAccessToken();
            profile = Profile.getCurrentProfile(); //Access the profile who Is the person login i
        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException e) {
            Log.i(TAG, " Error");
            Log.e(TAG, e.getMessage());
        }

    };

   public void setCallback(LoginButton lButton) {
       lButton = lButton;
       lButton.registerCallback(mCallbackManager, mCallback);
       Log.i(TAG, " setCallback called");
   }

And here Is my fragment-class:
Java:
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    fLogin = new FacebookLogin(getActivity().getApplicationContext());
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v =  inflater.inflate(R.layout.login, container, false);
    return v;
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState)
{
    super.onViewCreated(view, savedInstanceState);

    final LoginButton loginButton = (LoginButton) getView().findViewById(R.id.login_button);
    final TextView infoText = (TextView) getView().findViewById(R.id.text_details);

    loginButton.setFragment(this);


    loginButton.setReadPermissions("user_friends");

    loginButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.i(TAG, " Button clickde");
            fLogin.setCallback(loginButton); //Let's register a callback
            profile = fLogin.getProfile();
            if (profile != null) {
                Log.i(TAG, profile.getName()); //Call this after the callback request Is finished
            } else {
                Log.i(TAG, "NULL....... inside onresume");
            }
        }
    });

}

I want to call profile = fLogin.getProfile(); after the callback request is complete. But I don't know how to do this. I have read about the onComplete();, but I don't know how to Implement It here.
 
Back
Top Bottom