Android - Alarm lost after app update

前端 未结 2 1104
情话喂你
情话喂你 2020-12-16 19:45

I have an app running on Android that creates an alarm that is fired every 24 hours. This alarm is working as expected.

However, when I update my app through Google

2条回答
  •  猫巷女王i
    2020-12-16 20:47

    Your solution is as simple as below:

    Have a broadcast receiver registered within your app with 2 intent filters namely:

    1. "android.intent.action.BOOT_COMPLETED" - called when you device restarts. Alarms are cancelled when device is shut down.
    2. "android.intent.action.MY_PACKAGE_REPLACED" - called once your app is reinstalled or updated from play store or from any source.

    You will also need the permission, "android.permission.RECEIVE_BOOT_COMPLETED". In this receiver you can start your alarms again.

提交回复
热议问题