android - onPostExecute not executed -


i have asynctask class in app connects external database. after task (successfully) completed want start new activity.

mainactivity

public class mainactivity extends activity implements onclicklistener, postkey.asyncresponse {     postkey asynctask = new postkey();      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         asynctask.delegate = this;     }      public void processfinish(string output){         //this received result fired async class of onpostexecute(result) method.        string string;        string = "test";        log.d(string, " processfinish");     }      public void onclick(view v) {         keyvalue = key.gettext().tostring(); // declared @ top didn't include in snippet         string pattern = "^[a-za-z0-9]*$";          if(keyvalue.length() < 5){             new postkey().execute(keyvalue);         }     } } 

postkey

public class postkey extends asynctask<string, integer, double> {     public asyncresponse delegate = null;      @override     protected double doinbackground(string... params) {         postdata(params[0]);         return null;     }      //@override can't add override, doesn't override method superclass     protected void onpostexecute(string result){         delegate.processfinish(result);     }      public void postdata(string valueiwanttosend) {         httpclient httpclient = new defaulthttpclient();         httppost httppost     = new httppost("http:/www.domain.com/post.php");          try {             list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>();             namevaluepairs.add(new basicnamevaluepair("x", "test"));             httppost.setentity(new urlencodedformentity(namevaluepairs));              httpresponse response = httpclient.execute(httppost);             string responsestr = entityutils.tostring(response.getentity());              log.d(responsestr, ""); // gets logged              if(responsestr == "true"){                 delegate.processfinish(responsestr); // doesn't execute processfinish in mainactivity either             }         } catch (clientprotocolexception e) {             // todo auto-generated catch block         } catch (ioexception e) {             // todo auto-generated catch block         }     }      public interface asyncresponse {         void processfinish(string output);     } } 

//@override can't add override, doesn't override method superclass protected void onpostexecute(string result) 

take error hint: method signature wrong. should be

@override protected void onpostexecute(double result) 

or since you're not returning doubles, change result type declaration in extends asynctask<string, integer, double>.


Comments