Alarm set in App with AlarmManager got removed whe

2019-06-06 04:09发布

问题:

I am trying to create an alarm using AlarmManager it works fine even when device is locked.

But when I kill the application using Settings -> Manege App -> MyApp -> Force Stop then my alarm destroys all the settings.

So please tell me how to save my alarm settings after application is killed even by forced stop and it notifies me on its usual time.

Thanks in advance...

回答1:

But when I kill the application using Settings -> Manege App -> MyApp -> Force Stop then my alarm destroys all the settings.

AlaramManager is critical system service that runs all the time. And if your application scheduled something and was killed, then AlarmManager may start application again (via PendingIntent).

Just Check this Answer on StackOverflow.



回答2:

As of Android 3.1, if a user force closes your application, all alarms will be cancelled and will need to be rescheduled from within your code...

From Android Docs.... Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcast intents. It does this to prevent broadcasts from background services from inadvertently or unnecessarily launching components of stoppped applications. A background service or application can override this behavior by adding the FLAG_INCLUDE_STOPPED_PACKAGES flag to broadcast intents that should be allowed to activate stopped applications.

Applications are in a stopped state when they are first installed but are not yet launched and when they are manually stopped by the user (in Manage Applications).