GCM Network Manager does not perform tasks

1

Hello! Gentlemen, I have two tasks and I notice that the same ones are not being executed, I have called the same ones in the main activity in the onCreate (). However, if I go to another activity, the tasks are not called, detail is that of the two tasks one only executes only once One task does a GET and receives a json is a quick task, the other one gets data from the bank and does a POST, I'm using the loopj lib for the network.

    gnm = GcmNetworkManager.getInstance(this);

    PeriodicTask task1 = new PeriodicTask.Builder()
            .setService(AtualizacaoService.class)
            .setPeriod(50)
            .setFlex(10)
            .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
            .setRequiresCharging(false)
            .setUpdateCurrent(true)
            .setTag("atualizacao")
            .build();

    PeriodicTask task2 = new PeriodicTask.Builder()
            .setService(EnviarService.class)
            .setPeriod(80)
            .setFlex(10)
            .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
            .setRequiresCharging(false)
            .setUpdateCurrent(true)
            .setTag("envio")
            .build();

    gnm.schedule(task1);
    gnm.schedule(task2);

One of the services

public class AtualizacaoService extends GcmTaskService {
   private static final String TAG = "AtualizacaoService";

   private CustomSharedPreference shared ;
   private OrdemServicoService service ;
   private SincronismoService sincronismoService;
   private Sincronizacao sinc;
   private Date ultimaAtualizacao;
   private Map<String, String> params = new HashMap<String,String>();
   private SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy_HH:mm:ss", Locale.getDefault());

   @Override
   public void onInitializeTasks() {
       super.onInitializeTasks();
       Log.i(TAG, "onInitializeTasks()");
   }

   @Override
   public int onRunTask(TaskParams taskParams) {
       Log.i(TAG, "onRunTask()");
       retrieverUpdateFromRemoteServer();

       return GcmNetworkManager.RESULT_SUCCESS;
   }

   public void retrieverUpdateFromRemoteServer(){

    service = new OrdemServicoService(getApplicationContext());
    sincronismoService = new SincronismoService(getApplicationContext());
    User user = ((Aplicacao) getApplicationContext()).getLoginUser();

    params.put("data", sdf.format(this.ultimaAtualizacao)  );
    params.put(Helper.TOKEN, user.getToken());
    params.put(Helper.SERVIDOR, "1");

    CustomRequest serverRequest = new CustomRequest(
            Helper.PATH_TO_SERVER_ATUALIZACAO ,
            this.params,
            createRequestSuccessListener(),
            createRequestErrorListener());

    serverRequest.setRetryPolicy(new DefaultRetryPolicy(
            Helper.MY_SOCKET_TIMEOUT_MS * 2,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    VolleySingleton.getInstance(getApplicationContext()).addToRequestQueue(serverRequest);
}
    
asked by anonymous 03.11.2017 / 17:12

0 answers