App doesn't work on 4.0.3 but it works on 2.3.3

自作多情 提交于 2019-12-24 20:40:21

问题


I write an app and it works properly on android 2.3.3 , but it doesn't work on android 4.0.3.

I specify minsdk="10" and targetsdk="15" in my AndroidManifest file.

I am using .net web service in my app and I'm getting error on this page.

myspinner = (Spinner) findViewById(R.id.ihtiyacsec);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, SektorList);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        myspinner.setAdapter(adapter);

SektorList is null.

I'm using ksoap2 for access my web service.

Here is my function

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut=request;
        envelope.dotNet = true;     
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.debug = true;

       try {

       androidHttpTransport.call(SOAP_ACTION, envelope);
       SoapObject response = (SoapObject) envelope.getResponse();
       SektorList = new String[response.getPropertyCount()];

      for(int i=0;i<response.getPropertyCount();i++){          
               SektorList[i] = response.getPropertyAsString(i).toString();     
      }      
} 
        catch (Exception e) {           
            e.printStackTrace();
       }

When I debug the project , androidHttpTransport.call(SOAP_ACTION, envelope) is not work and compiler jump to catch block.

I know my soap action is true (same codes work in 2.3.3).

I dont know what is the problem ?


回答1:


Thats a very common problem. As of Android HC+ you aren't allowed to perform heavy network operations in your main UI thread. To solve this problem you could: remove the "targetsdk" tag from your manifest(not recommended) or just use an asynctask for your network operation.




回答2:


You're performing a (potentially slow) network operation on the main thread. If your target SDK is 11 (Honeycomb) or higher, this will throw a NetworkOnMainThreadException on Honeycomb or above, because this behaviour can block the UI and lead to an unresponsive app.

You could use an AsyncTask to get around this, loading the data in doInBackground(..).



来源:https://stackoverflow.com/questions/11865821/app-doesnt-work-on-4-0-3-but-it-works-on-2-3-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!