Wait Till Get My Id And My Friends Id Facebook
I want to wait till i get my user name and my id, and also to wait until I get the user names and users id of my friends in facebook. how can I implement it? I wrote a code after t
Solution 1:
For dependent threads, you can use a countdown latch : http://developer.android.com/reference/java/util/concurrent/CountDownLatch.html
Here is an example:
http://www.javacodegeeks.com/2011/09/java-concurrency-tutorial.html
Solution 2:
Using Android Facebook 3.0 setup the Fragment to manage the states using this tutorial
https://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/
You can use the prebuilt facebook login button to also login using the xml
<com.facebook.widget.LoginButton
android:id="@+id/authButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="51dp" />
Then either using the Session StatusCallback
https://developers.facebook.com/docs/reference/android/3.0/Session.StatusCallback or the overrides you created in the fragment in the previous tutorial you can initiate a call to retrieve your friends which would look like this
voidgetFriendsWithApp(final Intent intent){
finalProgressDialogmDialog=newProgressDialog(this);
mDialog.setMessage("Loading...");
mDialog.setCancelable(false);
mDialog.show();
StringfqlQuery="SELECT uid, name, pic_square FROM user WHERE uid IN " +
"(SELECT uid2 FROM friend WHERE uid1 = me())";
Bundleparams=newBundle();
params.putString("q", fqlQuery);
Sessionsession= Session.getActiveSession();
Requestrequest=newRequest(session,
"/fql",
params,
HttpMethod.GET,
newRequest.Callback(){
publicvoidonCompleted(Response response) {
try {
mDialog.dismiss();
TypelistType=newTypeToken<ArrayList<Friend>>(){}.getType();
Utils.friends = newGson().fromJson(response.getGraphObject().getInnerJSONObject().getJSONArray("data").toString(), listType);
startActivity(intent);
//This is where you would do what you want after you retrieve your json with friends
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
Request.executeBatchAsync(request);
}
Post a Comment for "Wait Till Get My Id And My Friends Id Facebook"