0

Is there a way to tell when a lock-screen widget is visible?

According to this related post, it was not possible 4 years ago in March 2010 for HOME screen widgets:

Since then Android has introduced lock-screen widgets, and I wonder if this functionality has also been introduced?

Community
  • 1
  • 1
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255

1 Answers1

0

I'm late, sorry. Android only updates widgets when they're enabled, so you don't have to worry about that.

I think you can't know when a Widget is visible because the main idea behind them is to be ever enabled, ever ready to be watched by the user. That's why there's no callback for what you're asking.

You should update your widgets from a Service or from the method onUpdate() from the class that extends AppWidgetProvider. Last option is not encouraged because is Android who decides when to update your widget, no matter how much time you have set up on updatePeriodMillis.

Lockscreen widgets are available since API 17 to 19. Lollipop (API 21) no longer leaves you to add widgets to the lockscreen. There's no direct callback neither.

Final words: You should design the widgets thinking that they have to be ever updated, no matter if they are visible or not because they could be visible in any moment.

Joaquin Iurchuk
  • 5,499
  • 2
  • 48
  • 64