request.setDisposeOnCompletion method

52 views
Skip to first unread message

Mario Barón

unread,
Oct 23, 2013, 10:28:37 AM10/23/13
to codenameone...@googlegroups.com
Hey guys, 

I have a smalll question, does the method request.setDisposeOnCompletion work only on the Dialog class or can it be used with classes that extend the Dialog class?  For me it seems to not be working with my own classes, does this have a workaround in case this can't be done? 

my code looks like this: 
DialogoEspera diag = new DialogoEspera();
    request.setDisposeOnCompletion(diag);


Thanks a lot for your answers. 

Mario Barón

unread,
Oct 23, 2013, 11:48:05 AM10/23/13
to codenameone...@googlegroups.com
Hey guys,

I've been testing my method in which I call this.. and looks like the problem is not with the dialog but with the request itself... 

  public void solicitarInformacionUbicacion(double latitud, double longitud, final Ubicacion ubicacion) {
    ConnectionRequest request = new ConnectionRequest() {
      Hashtable h;
      Vector ubicacionObtenida = null;
      String resultado;
      List<String> listResultado = null;

      @Override
      protected void postResponse() {
        System.out.println("Entró por post response");
        System.out.println("" + h.get("results"));
        ubicacionObtenida = (Vector) h.get("results");
        if (ubicacionObtenida != null) {
          for (int i = 0; i < ubicacionObtenida.size(); i++) {
            Hashtable elemento = (Hashtable) ubicacionObtenida.elementAt(i);
            System.out.println("Direccion formateada: " + elemento.get("formatted_address"));
          }
          resultado = "" + ((Hashtable) ubicacionObtenida.elementAt(0)).get("formatted_address");
          try {

            listResultado = Utilidades.getSplit(resultado, ",");
            ubicacion.setPais(listResultado.get(3));
            ubicacion.setCiudad(listResultado.get(1));
            ubicacion.setDireccion(listResultado.get(0));

            System.out.println("Pais " + listResultado.get(3));
            System.out.println("Ciudad " + listResultado.get(1));
            System.out.println("Direccion " + listResultado.get(0));
          } catch (Exception e) {

            e.printStackTrace();

          }

        }

      }

      @Override
      protected void readResponse(InputStream input) throws IOException {
        try {
          System.out.println("Entró por read response");
          JSONParser p = new JSONParser();
          h = p.parse(new InputStreamReader(input));

        } catch (Exception e) {
          h = null;
          e.printStackTrace();
        }
      }

      @Override
      protected void handleErrorResponseCode(int code, String message) {
        System.out.println("Error: " + code + " Mensaje: " + message);
      }

      @Override
      protected void handleException(Exception e) {
        System.out.println("Error: " + e.getMessage());
      }
    };
    
    request.setContentType("application/json");
    System.out.println("latitud: " + latitud + " longitud: " + longitud);
    request.setUrl("http://maps.googleapis.com/maps/api/geocode/json?latlng=" + latitud + "," + longitud + "&sensor=false");
    request.setPost(false);
    request.setHttpMethod("GET");

    NetworkManager netMgr = NetworkManager.getInstance();
    netMgr.setTimeout(3000);

    DialogoEspera diag = new DialogoEspera();
    request.setDisposeOnCompletion(diag);

    netMgr.addToQueueAndWait(request);

  }

It seems that it is never getting to the read response or any of the error methods... am I doing something wrong here? 

Thanks.

Shai Almog

unread,
Oct 23, 2013, 12:28:43 PM10/23/13
to codenameone...@googlegroups.com
Hi,
it works with every dialog.
You override handle error without calling super which might block dispose in a case of a failure. Other than that I can't think of an issue.

Mario Barón

unread,
Oct 23, 2013, 2:00:48 PM10/23/13
to codenameone...@googlegroups.com
Hey Shai,

thanks for your response. Jumm...that's weird I'm using the network monitor and seems to be that the request isn't even leaving at all, I think it may be stuck on queue. Is there a way I can know this?



On Wednesday, October 23, 2013 9:28:37 AM UTC-5, Mario Barón wrote:

Shai Almog

unread,
Oct 24, 2013, 12:52:41 AM10/24/13
to codenameone...@googlegroups.com
Are you using the show method of dialog rather than the modless show?

christop...@gmail.com

unread,
Aug 5, 2015, 9:35:07 AM8/5/15
to CodenameOne Discussions
A bit of an aged question but is seems the problem here was that NetworkManager was not started. In your case, this statement was missing:

    netMgr.start();

Shai Almog

unread,
Aug 5, 2015, 10:16:04 AM8/5/15
to CodenameOne Discussions, christop...@gmail.com
The network manager is started implicitly so no.
Reply all
Reply to author
Forward
0 new messages