*
Just learned Android and did a feature to record the problems encountered
1, when using the ListView, set the adapter adapter, forget the specific implementation within GetCount (), GetItem (), Getitemid () method, resulting in window leaked error
At first I thought there was a dialog box without hide
2, from the request to the process of displaying the data
The Android client sends a request to encapsulate the data in JSON format, typically starting a sub-thread to request, by connecting the WebService interface, calling the WebService published interface method,
Parse data parameters in JSON format, perform operations such as adding and removing database additions and deletions, returning results to JSON format, processing returned data in callback functions, modifying display pages as needed
Here's how to connect WebService
Public Static Final voidTranscall (Handler handler,string methodName,intSoapversion,Booleanisdotnet, Map<string, object>Property ) { /*** Name Space*/String NAMESPACE=Instance.getnamespace (); /*** WebService provides interface <br/> * For example: Java wsdl-->http://192.168.1.117: 10101/services?wsdl*/String ENDPOINT=Instance.getendpoint (); Message Message=Message.obtain (); Message.what=Webservicestatecode.response_server_error; String SOAPAction= NAMESPACE +MethodName; Httptransportse Transport=NewHttptransportse (ENDPOINT, 20000); //specifies the namespace of the WebService and the method name of the callSoapobject RPC =NewSoapobject (NAMESPACE, methodName); if(Property! =NULL&&!Property.isempty ()) {Set<String> keys =Property.keyset (); for(String key:keys) {rpc.addproperty (key, Property.get (key)); } } //generates SOAP request information that calls the WebService method and specifies the version of SoapSoapserializationenvelope envelope =NewSoapserializationenvelope (soapversion); Envelope.bodyout=RPC; //sets whether to invoke the dotnet developed WebServiceEnvelope.dotnet =isdotnet; //equivalent to envelope.bodyout = RPC;envelope.setoutputsoapobject (RPC); Booleancalled =false;//identifies whether the WebService request succeeded Try { //Call WebServiceTransport.call (soapaction, envelope); Transport.getconnection (). disconnect (); Called=true; } Catch(IOException e) {message.obj= "The network cannot connect." "; } Catch(xmlpullparserexception e) {message.obj= "resolves the server-side XML file exception. "; } if(called) {//WebService Request succeeded// //get the returned dataSoapobject Object =(Soapobject) Envelope.bodyin; Soapprimitive Resultsoap= (soapprimitive) object.getproperty ("Result"); if(Resultsoap! =NULL) { Try{jsonobject result=NewJsonobject (resultsoap.tostring ()); String StatusCode= Result.getstring ("StatusCode"); if(Statuscode.equals ("200")) {//server-side request response succeeded if(Result.has ("MSG") ) {Message.obj= Result.getjsonobject ("msg")); } message.what=WEBSERVICESTATECODE.RESPONSE_OK; } Else if(Statuscode.equals ("403") ) {Message.what=Webservicestatecode.response_forbidden; } Else if(Statuscode.equals ("500") ) {Message.what=Webservicestatecode.response_server_error; } } Catch(jsonexception e) {message.obj= "JSON format data get exception." "; }}} handler.sendmessage (message); }
My understanding:
First, letter A gives B
Equivalent to setting an address on an envelope to find a way to get a webservice
String soapaction = NAMESPACE + methodName; Http://service.webservice.magnetic.com/login
Equivalent to a postman
Httptransportse transport = new Httptransportse (ENDPOINT, 20000);
Envelope, written on the ZIP code
Soapserializationenvelope envelope = new Soapserializationenvelope (
Soapversion);
Soapobject RPC = new Soapobject (NAMESPACE, methodName);
Set parameters, construct the contents of the letter
if (property = null &&!property.isempty ()) {
set<string> keys = Property.keyset ();
for (String Key:keys) {
Rpc.addproperty (Key, Property.get (key));
}
}
Envelope.bodyout = RPC; Write the content on the letter
Call WebService
Transport.call (soapaction, envelope); The postman went to deliver the letter, the envelope address (soapaction) and the envelope (envelope, already written)
So the messenger is done.
Then, B has replied to a
Get the returned data
Soapobject object = (soapobject) Envelope.bodyin; Get the reply content
Generally according to their own packaging principles such as:
findlistforsqlresponse{result={"msg": {"result": [{"0": "AAA", "1": "1.3", "2": "/ANDROID/VMARK_1.3.APK"}]}, " StatusCode ":" 200 "}; }
Then various ways to remove JSON-formatted data
Finally, don't forget handler.sendmessage (message);
This is the callback that sends the result to the person who has been waiting for the result (handler), and then calls the Handlemessage () method automatically
3, do the background message push, mainactivity start Service,service in the Onstartcommand () method query, the results of the query returned in the callback processing class in the form of a message pushed this data
The method that calls WebService does not execute correctly, and even breakpoints cannot be entered
The reason is that the service error is configured in Androidmanifest.xml.
The following is a call to third-party webservice using
< Service Android:name = "COM.BAIDU.LOCATION.F" android:enabled= "true" android:process= ": Remote"> </service>
The following is a call to the local
<Serviceandroid:exported= "false"Android:name= ". Service. Newupdateservice "android:enabled= "true" > <Intent-filter> <ActionAndroid:name= "Com.magnetic.market.service.NewUpdateService" /> </Intent-filter> </Service>
*
Android First Use