BroadcastReceiver cuando la aplicación no se está ejecutando

Tengo un BroadcastReceiver registered in the manifest which receives notifications from the AlarmManager. This all works great while the app is running i.e. the onReceive() se está llamando al método.

However, if I force-stop the app so that I can test if the BroadcastReceiver will still receive notifications from the AlarmManager while not running, the onReceive() nunca se llama al método.

Can force-stop not be used to test the AlarmManager & receiver in this way? There seems to be some responses saying it won't work, and some saying it should.

If not, is there a way of testing this?

preguntado el 22 de mayo de 12 a las 18:05

¿Ha definido su BroadcastReceiver on the manifest? -

@jFort : Are you using one of the WAKEUP types for the alarm? If not then that might be the cause but I'm not sure. -

Yes, the broadcast receiver is defined in the manifest. And the alarm manager is defined AlarmManager.RTC -

@jFort : Only RTC? No RTC_WAKEUP? -

I think RTC_WAKEUP will wake the device but they're only simple reminders so that's not what I'm intending to do. -

3 Respuestas

If your receiver is registered in your manifest, it should always work. Even if your app is force closed.

The problem might be the alarm. The alarms might be getting deleted, once your app force closes.

contestado el 22 de mayo de 12 a las 18:05

For android > version 3.0, your receiver will stop working when your app is force closed! - Hoang NguyenHuu

As Hoang says, this answer has not been correct for many years, and many Android versions. - Richard Le Mésurier

i am not using Alarm Manager i am using call / phone state broadcast receiver i am getting issue is when app is not running at that time call broadcast not getting - Tanque Mehul

Did you fin\d any solution? I face same issue @MehulTank - Brinda Rathod

@BrindaRathod You can add android:enabled="true" android:exported="true" intent-filter android:priority="999" - Tanque Mehul

Según los comentarios de esta respuesta, you cannot test this type of thing by killing the app yourself. You must throw an exception so the app dies "naturally".

contestado el 23 de mayo de 17 a las 13:05

May this could be your device problem. In Xiomi, Oppo, Vivo, honor, and Letv mobiles user has to give an autostart permission to the application and for this, you should ask the user to enable this manually you cant done it programmatically

respondido 22 nov., 18:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.