Android: Same response in Toast for async task onpostexecute()
I am deling with web services and I got a problem with my Toast in onpostexecute() method. I am trying to show the toast according to the logcat response.resultsRequestSOAP is a string value I am retrieving from server. If the string value is 1 then I should show "registerd" in toast. If 0 then "Try again" and If -1 then "Field is empty"
In my logcat I m getting the response as string value.
The problem is every time I am getting "Try again" toast message.
The problem might be with Boolean(which I m using) instead of primitive value which never returns null. I m confused with this line else if (resultsRequestSOAP.booleanValue()). its not working for me. how to solve this?
plz some one check the code in onpostexecute() and let me know the problem.
I want to compare the value in logcatand show the toast like this. If its 1 then "Registered", If its 0 then "Try again", If its -1 then "field should not be empty"
Help is always appreciated...!
public class Register extends Activity {
public static final Boolean resultsRequestSOAP = null;
@Override
public void onCreate(Bundle sa开发者_如何学运维vedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
private class RegisterTask extends AsyncTask<Void, Void, Boolean> {
private final ProgressDialog dialog = new ProgressDialog(Register.this);
protected void onPreExecute() {
this.dialog.setMessage("Registering...");
this.dialog.show();
public Boolean register() {
// code for webservices********
}
return resultsRequestSOAP;
protected void onPostExecute( Boolean resultsRequestSOAP) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
if (resultsRequestSOAP == null) {
Toast.makeText(Register.this.getApplicationContext(), "Try Again", Toast.LENGTH_SHORT).show();
}
else if (resultsRequestSOAP.booleanValue()) {
//also show register success dialog
Toast.makeText(Register.this.getApplicationContext(), "Registerd", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(Register.this.getBaseContext(), "Field is empty", Toast.LENGTH_SHORT).show();
}
super.onPostExecute(resultsRequestSOAP);
}
protected void onPostExecute( Boolean resultsRequestSOAP) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
sendResult(resultsRequestSoap);
super.onPostExecute(resultsRequestSOAP);
}
put this method on outer class
public void sendResult(String resultsRequestSoap){
if (resultsRequestSOAP == null) {
Toast.makeText(this, "Try Again", Toast.LENGTH_SHORT).show();
}
else if (resultsRequestSOAP.booleanValue()) {
//also show register success dialog
Toast.makeText(this, "Registerd", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(this, "Field is empty", Toast.LENGTH_SHORT).show();
}
}
精彩评论