Android的不断广播接收器,而应用程序被关闭
我使用ACTION_BATTERY_CHANGED的广播接收器,每次获得一个事件的电池为50%。我不能在申报清单ACTION_BATTERY_CHANGED,所以我宣布一个服务的广播接收器(START_STICKY)。
I use BroadcastReceiver of ACTION_BATTERY_CHANGED to get an event every time the battery is 50%. I can't declare ACTION_BATTERY_CHANGED in manifest, so I declared the BroadcastReceiver in a Service (START_STICKY).
但是,当我删除的应用程序最近的应用程序筛选的BroadcastReceiver停止越来越更换电池事件。
我怎样才能保持它在后台?
But, when I remove the app from recent apps screen the BroadcastReceiver stops getting battery change events. How can I keep it in background?
*在许多应用程序,在状态栏显示电池%,而应用程序被关闭的百分比被更新。怎么样?
*In many apps that show battery percent in status bar, the percent is updated while the app is closed. How?
您真的不能做你正在尝试做的。有没有办法让你的应用程序运行下去,你只能抓ACTION_BATTERY_ *您的应用程序运行的位置。
You really cannot do what you are trying to do. There is no way to keep your application running forever, and you can only catch ACTION_BATTERY_* where your app is running.
由于广播是粘性的,不过,你可以做别的事情。让你醒来你的应用程序设置了一个报警(AlarmManager),定期。当您注册一个接收器,在code,Android将交付,而你的应用程序没有运行播出的任何意图。
Since the broadcast is sticky, though, you can do something else. Set an alarm (AlarmManager) so that you wake your app up, periodically. When you register a receiver, in your code, Android will deliver any intents that were broadcast while your app was not running.