Vänta tills ett callback-request är klart, Android + Facebook SDK

Permalänk
Medlem

Vänta tills ett callback-request är klart, Android + Facebook SDK

Hejsan,

Jag har följande class som instansieras av min fragment-klass:

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"); }

Här är min fragment-klass:

@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"); } } }); }

Det jag vill göra nu är att anropa fLogin.getProfile() efter att callback-requestet är klart. Dock så vet jag inte riktigt hur jag ska kolla när requestet är klart. Jag har kollat lite på onComplete(), men vet dock inte hur jag skall implementera det.

Någon som kan hjälpa?

Visa signatur