i’m trying to post on facebook so i’m uising the following code. It works well, but I can’t seem to post a simple confirmation toast.
private class FacebookPoster extends AsyncTask<String, Object, Object>
{
@Override
protected Object doInBackground(String... message)
{
Bundle parameters = new Bundle();
parameters.putString("message", message[0]);
parameters.putString("description", "topic share");
parameters.putString("link", ctx.getResources().getString(R.string.rateLink));
parameters.putString("picture", ctx.getResources().getString(R.string.linkIconPicture));
Log.d("ERRRR", "set params");
try
{
facebook.request("me");
String response = facebook.request("me/feed", parameters, "POST");
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") || response.equals("false"))
{
return "Blank response.";
}
else
{
return "Message posted to your facebook wall!";
}
}
catch (Exception e)
{
return "Failed to post to wall!";
}
}
@Override
protected void onProgressUpdate(Object... values)
{
// TODO Auto-generated method stub
super.onProgressUpdate(values);
showToast(values);
}
}
showToast function
private void showToast(Object message)
{
Toast.makeText(ctx, message.toString(), Toast.LENGTH_SHORT).show();
}
I think the onProgressUpdate is not called. Please help.
onProgressUpdateis made for updating your progress-bar for example when the code is still running, and you need to callonProgressUpdatemanual, using thepublishProgressmethod.You are returning a string (Object) in the
doInBackgroundmethod. This string will be send to theonPostExecutemethod.So what you should do is remove the
onProgressUpdatemethod, and override theonPostExecutemethod and put the Toast code inside it.Note:
onProgressUpdateandpublishProgressshould only be used for updating progress while the background task is still running, not for showing the final result. For the final result you use theonPostExecutemethod.http://developer.android.com/reference/android/os/AsyncTask.html