I am posting something to FB from my program.
Works great except that I want to show a ProgressDialog before and then an AlertDialog after.
For some reason the ProgressDialog doesn’t appear at all whereas the AlertDialog does but the execution of the code continues through and doesn’t “wait”.
private void uploadToFB(){
if (settings.getCurrentUploadToFB()){
ProgressDialog progressDialog = ProgressDialog.show(this, "Posting to Facebook", "Please wait ...", true);
Bundle parameters = new Bundle();
parameters.putString("link","https://market.android.com/details?id=il.co.anykey.games.yaniv.lite&feature=search_result");
parameters.putString("picture","http://www.anykey.co.il/images/launcher_yaniv.png");
parameters.putString("name","YanivLite on Android");
parameters.putString("caption","Can you beat my score?");
parameters.putString("description","I scored "+ ScoringForScoreloop.getScore() + " in YanivLite on Android. Can you beat my score?");
facebookConnector.postMessageOnWall(parameters);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(R.string.uploadedToFacebookTitle);
ScoringForScoreloop.addAssafedScore();
alertDialog.setMessage(getString(R.string.uploadedToFacebookMessage));
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE,getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
try {
alertDialog.dismiss();
finishGame();
} catch (Exception ex) {
ex.printStackTrace();
}
return;
} });
alertDialog.setCancelable(false); // prevent use of back button which would skip the listener
alertDialog.show();
}
else
finishGame();
}
try this class