HonyComb and DefaultHttpClient

后端 未结 4 887
情话喂你
情话喂你 2020-12-03 11:29

In my code I have this

        Log.d(\"WFlog (executeRequest)\", request.toString()) ;
        httpResponse = client.execute(request);  
        Log.d(\"WFlo         


        
4条回答
  •  悲&欢浪女
    2020-12-03 12:13

    I used an asynctask, saw it in other threads, and it worked fine....i create a subclass where i wanted to call the network connection. i don't know if it is the best way but this code worked for me....

    public miclase{
    
        public boolean comprobarMP3(int canal){
            boolean retorno=true;
            //This commented Code is what it was NOT working
            //swr= new ServicioWebRest();
            //contenido=swr.obtieneContenido(Channels.getInstance().getChannel().get(canal).getId());
            try{
               //this.get() was important, i had troubles in recovering the objet, .get() solved it
                contenido=new getContenidoAsync().execute(canal).get();
            }catch(Exception e){
                contenido=null;
            }
        }
    
        //Clase interna para acceder a los webservice de un modo asincrono en otro hilo
        //Desde el sdk 11, las politicas de seguridad de android no permiten acceder a internet desde el hilo principal 
        public class getContenidoAsync extends AsyncTask{
            Contenido c=new Contenido();
    
            @Override
            protected Contenido doInBackground(Integer... urls) {
            //aqui el codigo q sea, yo llamo a este que llama a otra clase que es el q llama a http 
                return new ServicioWebRest().obtieneContenido(Channels.getInstance().getChannel().get(urls[0]).getId());
            }
    
            @Override
            protected void onPostExecute(Contenido result) {
                c=result;
            }       
        }
    }
    

提交回复
热议问题