Reputation: 57
Everything is working fine but the Toast from the onProgressUpdate is not showing up. I am surely doing something wrong. Please help me out. The Code is:
private class MyTask extends AsyncTask<String, String, String> {
protected String doInBackground(String... params) {
publishProgress("Sending...");
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.projectyourself.96.lt/android.php");
//HttpPost httppost = new HttpPost("http://www.yembed.in/loans4you/form.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("message", params[0]));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
}catch (Exception e){
return "fail";
}
return "sent";
}
protected void onProgressUpdate(String i) {
super.onProgressUpdate(i);
Toast.makeText(getBaseContext(),i,Toast.LENGTH_SHORT).show();
}
protected void onPostExecute(String r) {
if(r=="sent") {
t.setText("");
Toast.makeText(getBaseContext(), "Sent", Toast.LENGTH_SHORT).show();
}
else
Toast.makeText(getBaseContext(),"Not Sent!",Toast.LENGTH_SHORT).show();
}
}
Upvotes: 0
Views: 323
Reputation: 73
The parameter in the method onProgressUpdate(String... values) has to be an array. You created a whole new method that is never actually called.
To fix your problem, change this:
protected void onProgressUpdate(String i) {
super.onProgressUpdate(i);
Toast.makeText(getBaseContext(),i,Toast.LENGTH_SHORT).show();
}
to this:
protected void onProgressUpdate(String... i) {
super.onProgressUpdate(i);
Toast.makeText(getBaseContext(),i[0],Toast.LENGTH_SHORT).show();
}
Upvotes: 1