Automatic sync without consuming too much memory - Android

0

I have an application that has been running for quite some time, but I have been asked to put in a function to send the data automatically. The problem is that it ends up using a lot of memory in the smart because the timer stays running and ends up often closing the app. They could help me by explaining to me a better way to do this synchronization, best practices, or something like that.

Follow the code

        int delay = 1800000;   // delay de 30 min.
        int interval = 600000;  // intervalo de 10 min.

        Timer timer = new Timer();

        timer.scheduleAtFixedRate(new TimerTask() {
            public void run() {
                try {
                    if (Util.verificaConexaoWIFI(EntradaActivity.this) == true || Util.verificaConexaoGPRS3G(EntradaActivity.this) == true) {

                        PalmPedidoVendaDAO pedido = new PalmPedidoVendaDAO(EntradaActivity.this);

                        if (pedido.getListaPedido() != null) {
                            if (statusSincronizacao == 1) { // Verifica se a sincronização está liberada 
                               // Envia os dados para o webservice
                            }
                        }
                    }

                }catch (Exception e){
                    throw new RuntimeException("SEM CONEXÃO COM A INTERNET ! " + e.getMessage());
                }
            }
        }, delay, interval);
    
asked by anonymous 16.10.2018 / 15:12

0 answers