How to detect if a widget is on/off screen?

拥有回忆 提交于 2019-12-07 18:20:34

I don't think you can. The framework will just send you an onUpdate request when the widget is created, and then again according to your update policy.

I don't see why there would be a reason to change the image when the widget isn't being shown. You're not saving the OS any resources by doing so; it already knows not to draw your widget when it's off-screen.

You can use the following from Android 2.1 an onwards to check if the screen is on.

PowerManager mPower = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
boolean screen_is_on = mPower.isScreenOn();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!