Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
644 views
in Technique[技术] by (71.8m points)

alarmmanager - How to reset alarm if app is force closed in android

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 process.
  3. Android itself killed my app, because of the need of memory for front apps.

Please tell me how do I detect it? rather how to set my alarms so that all these cases dont affect my alarms.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...