4

I'm trying to update my Android app based on the date.

So, for example, if it's a certain date show some information about that date.

Or, when it's a new week, do a couple of things in the background.

How do I do this?

Do I check constantly for the date? Is there a "flag" when the date has changed?

Thanks.

Aman Chhabra
  • 3,824
  • 1
  • 23
  • 39
amitairos
  • 2,907
  • 11
  • 50
  • 84

1 Answers1

2

You can use brodcast receiver like ACTION_DATE_CHANGED

More details can be found at https://developer.android.com/reference/android/content/Intent.html#ACTION_DATE_CHANGED

Answer to more questions:

1) For specific date you can have check within onReceive method. 2) To schedule it at a different time or do other stuffs after particular days, you can also use Alarm Service like in the below link:

Android - How to set a notification to a specific date in the future?

Community
  • 1
  • 1
Aman Chhabra
  • 3,824
  • 1
  • 23
  • 39
  • Thanks. But how do I check for a specific date? Should I just do an if statement inside onReceive? Also, how do I check for a new week? And, is there an option to check at a different time than midnight? – amitairos Jul 03 '16 at 17:51
  • 1
    Answer update. Accept as answer if it helps you so that other can also use the same answer. Cheers! – Aman Chhabra Jul 03 '16 at 18:08
  • @amitairos Try the code I've made here: https://stackoverflow.com/a/48782963/878126 . For special date checks, you can use the LocalDate that you receive. It has plenty of functions. – android developer Feb 14 '18 at 09:14
  • `ACTION_DATE_CHANGED` will be called only when you change the date manually from settings. If date is changed automatically by the clock, so from 23:59 -> 00:00 than this will not be called. – Torima Apr 14 '22 at 11:08