I'm writing an Android app widget that updates every minute with the current data. To update it, I'm using an AlarmManager
that only works while the phone is not asleep:
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), INTERVAL_SEC * 1000, createFrequentUpdateIntent(context));
However, I'm facing the following challenge: when the phone wakes up after a long time, I want the user to see immediately that the data is obsolete because it hasn't been updated for hours. So I want to somehow mark the data as obsolete if there have been no updates for a long time.
I thought about hooking on the SCREEN_ON
event, but apparently this is only possible through a background service and this is strongly discouraged (here and here).
Do you have any ideas of how to do this?
Thanks!