java - ksoap2 - Same method works wih AsyncTask but no when using inside normal activity -


i'm developing app , has funcionality can used user in 2 different ways: task in real time, he/she have wait till task finishes; or task in background he/she can other things in meanwhile.

i've developed task in background asynctask , works, don't know why i'm getting , error when try call same method inside normal activity.

this method uses ksoap2, value of param i'm testing "http://www.google.com"

public string sendurl(string url) {     log.i("url", url);     //create request     soapobject request = new soapobject(namespace, method_name);     request.addproperty("url", url);      //create envelope     soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11);     envelope.dotnet = false;     envelope.implicittypes = true;     envelope.setaddadornments(false);     envelope.setoutputsoapobject(request);      //create http call object     httptransportse androidhttptransport = new httptransportse(url);     androidhttptransport.debug = true;     androidhttptransport.setxmlversiontag("<!--?xml version=\"1.0\" encoding= \"utf-8\" ?-->");      soapprimitive response = null;     try {         //invoke web service         androidhttptransport.call(soap_action, envelope);  // here i'm getting error         //get response         response = (soapprimitive) envelope.getresponse();         // return response         return response.tostring();     } catch (socketexception e) {         e.printstacktrace();         // todo error, el servidor no esta levantado     } catch (ioexception e) {         e.printstacktrace();     } catch (xmlpullparserexception e) {         e.printstacktrace();     } catch (nullpointerexception e) {         e.printstacktrace();     }     return null; } 

this output error i'm getting android studio:

03-28 09:25:50.291 17894-17894/es.sia.urlanalyzer w/system.err: java.net.malformedurlexception 03-28 09:25:50.291 17894-17894/es.sia.urlanalyzer w/system.err:     @ java.net.url.<init>(url.java:152) 03-28 09:25:50.291 17894-17894/es.sia.urlanalyzer w/system.err:     @ java.net.url.<init>(url.java:125) 03-28 09:25:50.291 17894-17894/es.sia.urlanalyzer w/system.err:     @ org.ksoap2.transport.serviceconnectionse.<init>(serviceconnectionse.java:39) 03-28 09:25:50.291 17894-17894/es.sia.urlanalyzer w/system.err:     @ org.ksoap2.transport.httptransportse.getserviceconnection(httptransportse.java:104) 03-28 09:25:50.291 17894-17894/es.sia.urlanalyzer w/system.err:     @ org.ksoap2.transport.httptransportse.call(httptransportse.java:61) 03-28 09:25:50.291 17894-17894/es.sia.urlanalyzer w/system.err:     @ es.sia.urlanalyzer.analyze.sendurl(analyze.java:377) 03-28 09:25:50.291 17894-17894/es.sia.urlanalyzer w/system.err:     @ es.sia.urlanalyzer.analyze$1.onclick(analyze.java:167) 03-28 09:25:50.291 17894-17894/es.sia.urlanalyzer w/system.err:     @ android.view.view.performclick(view.java:5198) 03-28 09:25:50.291 17894-17894/es.sia.urlanalyzer w/system.err:     @ android.view.view$performclick.run(view.java:21147) 03-28 09:25:50.291 17894-17894/es.sia.urlanalyzer w/system.err:     @ android.os.handler.handlecallback(handler.java:739) 03-28 09:25:50.291 17894-17894/es.sia.urlanalyzer w/system.err:     @ android.os.handler.dispatchmessage(handler.java:95) 03-28 09:25:50.292 17894-17894/es.sia.urlanalyzer w/system.err:     @ android.os.looper.loop(looper.java:148) 03-28 09:25:50.292 17894-17894/es.sia.urlanalyzer w/system.err:     @ android.app.activitythread.main(activitythread.java:5417) 03-28 09:25:50.292 17894-17894/es.sia.urlanalyzer w/system.err:     @ java.lang.reflect.method.invoke(native method) 03-28 09:25:50.292 17894-17894/es.sia.urlanalyzer w/system.err:     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726) 03-28 09:25:50.292 17894-17894/es.sia.urlanalyzer w/system.err:     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616) 

the same method, same, working fine in custom class extends asynctask. values of soap calls web service are:

string namespace = "http://10.0.2.2:4894/analyzeurl_ws/services/"; string url = "http://10.0.2.2:4894/analyzeurl_ws/services/analyzeurl"; string soap_action = "http://10.0.2.2:4894/analyzeurl_ws/services/analyze"; string method_name = "analyze"; 

the reason quite simple, cannot run network activities on main thread/ui thread. network activities should run on background service in order not interfere u.i processes, if allowed user have wait network process completed before proceeding using app. bad practise, example if want upload alot of data fetching users message box, , have 1000 messages, if process allowed on ui thread, take time, when run upload service in background, user can comfortable use other features of app while data being uplaoded. therefore network activities restricted taking place in main thread, if network relate exception.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -