Android Service with Firebase takes a few hours to answer

0

good morning

I'm on android 8 Oreo and I need my service to always run in the foreground; so far it is not destroyed, since I execute it with startForegroundService along with a Notification of IMPORTANCE_HIGH within the first 5 seconds, but after a few hours when sending a signal to the service which consists of changing a data in the Firebase database, the service takes time to activate

the service I execute with a START_REDELIVER_INTENT ; and in destroy I have it with a broadcast in case it were destroyed, which does not happen; it only takes a few hours after responding to run an action because of the changed value in the database.

Will there be anything else that you have to consider so that the service is maintained with full priority or very attentive to receive a signal?

  

SERVICE

 @Override
public int onStartCommand(Intent intent, int flag, int idProcess) {
    super.onStartCommand(intent,flag,idProcess);

    // Consulta a la base de datos de firebase en tiempo real
    CONSULTA = new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

            for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) {

                if (postSnapshot.getKey()).equals("estado"){

                    valorEstado = (postSnapshot.getValue()).toString();

                    //*** verifica el valor
                    if (valorEstado.equals("desactivada")) {
                        Log.i("TAG", "VALOR ESTADO: DESACTIVAR");

                    } else {
                        if (valorEstado.equals("activada")) {
                           Log.i("TAG", "VALOR ESTADO: ACTIVAR");

                        }}}}}
    myRef.addValueEventListener(CONSULTA);
    
asked by Ivan Vidal 09.07.2018 в 14:17
source

0 answers