android - How to do or do nothing base on AsyncTask result? -


experts,

my goal simple, input address, click button test url, if not expected result, toast info , nothing. if expect result, continue program.

since can not use url in ui thread, used asynctask, problem is: though know result asynctak, how inform activity or nothing? want statement inside onclicklistener this:

if (result not expected) return; else continue things. 

i cannot write above statement in onpostexecute, return onpostexecute(), not onclicklistener().

another is: if can pass result activity(namely onclicklistener()), when result arrives, ui thread run other codes, shouldn't before knowing result.

in short, need url result decide how run remaining codes, therefore cannot use async task, should do?

thanks.

below example code:

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      btnconfirm.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {          new xxx().execute(code);  });  }    class xxx extends asynctask<string, void, string> {     protected string doinbackground(string... strarr) {         xxxxx;     }      protected void onpostexecute(string result) {         xxxxx;     } } 

this should easy. try approach:

since have asynctask inner class in activity, can return result in onpostexecute() check if request successful or not.

now, here final part: create method in activity this:

private void executeonasyncsuccess(){    //place code here want run } 

now can call inside onpostexecute() easily!

you can using events approach should work!

i hope helps!


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -