How to stop service when ACTION_SCREEN_OFF

前端 未结 4 1879
礼貌的吻别
礼貌的吻别 2021-01-14 11:56

I am trying to make my UpdateService for my digital clock widget stop when the screen is turned off to conserve battery, and then back on when the screen is activated. I cur

4条回答
  •  醉酒成梦
    2021-01-14 12:33

    It seems you cannot register for the ACTION_SCREEN_ON/OFF intents with a filter in the manifest. You have to register your BroadcastReceiver in code. See here for an examples for an activity and a service.

    You'll only receive the intent if your service or activity is running. In contrast to other broadcast events, the system will not start your process to handle the SCREEN_ON intent. It is similar to ACTION_BATTERY_CHANGED in this regard.

    To handle this intent with a widget, I think you have to start a service that listens for the intent and then notifies your widget.

提交回复
热议问题