How to reset alarm if app is force closed in android

后端 未结 1 1932
迷失自我
迷失自我 2020-12-01 15:27

The alarms set by my app using AlarmManager are cleared if

  1. The user force closes my app in the settings.
  2. Some task killer app auto-killed my app proc
相关标签:
1条回答
  • 2020-12-01 15:35

    The user force closes my app in the settings.

    Yes, this clears alarms.

    Some task killer app auto-killed my app process.

    This does not clear alarms on any recent version of Android.

    Android itself killed my app, because of the need of memory for front apps.

    This does not clear alarms.

    Please tell me how do I detect it?

    Maintain a record of when your alarm last occurred (e.g., in SharedPreferences). When your code runs (e.g., LAUNCHER activity is started), check the last-alarm time. If it was a long time ago, you know that your alarms were cleared, and so you need to reschedule them.

    rather how to set my alarms so that all these cases dont affect my alarms.

    This is not possible. There are few cases where the alarms actually are cleared (reboots and Force Stop), and there is nothing you can do to prevent your alarms from being cleared in those cases.

    0 讨论(0)
提交回复
热议问题