Android Broadcast receiver not executed on application close

前端 未结 2 1071
情书的邮戳
情书的邮戳 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:26

    You have to add your app in the Android Settings > Protected Apps section on the phone. This lets the user control which apps to allow running in the background.

    You could also write a service to listen to the location broadcasts which will run in the background without problem if you get the necessary permissions.

    0 讨论(0)
  • 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 <intent-filter>) 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.

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