Android-rest-ListView

0

ANdroid - Rest Services I need to invoke a restful service after clicking on a record in the ListView. The application restarts without marking error. If this event is handled by a button, it correctly consumes the service. They can help me see what I'm doing wrong, I can not identify what it is !!

    public ListView epclist;
    onCreate
   .
   .
   epclist.setOnItemClickListener(new OnItemClickListener()
    {
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
        long arg3)
      {
       buscarTag(arg1,"2DEC14DC6496B100000000E3");
      }
    });
    .
    .
    end onCreate

   public void buscarTag(View view,String tag) {

    String url = String.format("http://192.168.1.66:9090/miservicio/rest/rfid/getTickets/2DEC14DC6496B100000000E3");

    new LoadFilmTask().execute(url);

    }

   private class LoadFilmTask extends AsyncTask<String, Long, String> {

    protected String doInBackground(String... urls) {
        try {
            return HttpRequest.get(urls[0]).accept("application/json")
                    .body();
        } catch (Exception exception) {
            return null;
        }
    }

    protected void onPostExecute(String response) {
        respuesta =response;
     }
    }
    
asked by Ricardo Trejo 09.05.2017 в 16:38
source

1 answer

0

Better use Thread .. send the request in a thread .. this may be your problem .. that sometimes the network is slow .. therefore Android can not wait long and close the application

     Thread thread= new Thread(){
        @Override
        public void run() {
            >...aqui tu peticion HTTP
        }
    };thread.start();
    
answered by 10.05.2017 в 00:18