android - AsyncTask doInBackground returns too soon -


i have asynctask connecting websocket.

protected void doinbackground() {    client.connect();   return null; } 

when it's finished attempting connection, want following happen (currently inside onpostexecute):

protected void onpostexecute() {   if (socketconnected) {     dootherthings();   } else {     log("failed connect.");   } 

i've tossed in following, probe of sorts (in websocketclient implementation):

public void onopen() {   log("opened successfully!");   socketconnected = true; } 

the onpostexecute method prints failure message , followed success message onopen. suggests doinbackground returning soon. there common reason might happen?

yes, method client.connect() creates asynctask , leaves task continue executation, ending method , going onpostexecute.

if thats case, api using should have methods listening async messages. api should have listener or callback fired @ thread.

edit: searched webviewclient on internet , method connect() indeed creates new thread, should how use calls properly.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -