Android Broadcast receiver not executed on application close

前端 未结 2 1072
情书的邮戳
情书的邮戳 2021-01-12 16:36

I have an android application, where I schedule to an event (location update) to be executed in the future using Alarm manager. The scheduled event executes as expected as l

2条回答
  •  别那么骄傲
    2021-01-12 17:38

    But once I force close the application under task manager or when android system kills the application due to memory issue when the app is at background, I am no longer able to receive the broadcast from the alarm manager.

    These have nothing to do with each other, so if you have been simulating "when android system kills the application due to memory issue" by using Force Stop, that is your problem. An app that has been force-stopped through Settings has its alarms removed, among other things. A better way to simulate your process being terminated is to terminate it from DDMS.

    1) Intent.Flag_Include_Stopped_Packages 2) receiver android:process=":remote" in manifest 3) receiver android:exported="true" in manifest

    None of those are related to your problem, and android:exported="true" (and your use of an ) raises security issues, as now anyone can cause your BroadcastReceiver to be run at any time, for any reason.

    Here is a sample application that successfully processes alarm events, even after the process has been terminated by DDMS.

提交回复
热议问题