Maxime Tant Maxime Tant - 1 year ago 109
Android Question

Android : Decrement a variable daily

Heyyy, I know how to save variables and other data in SharedPreferences, but I like to know how it would be possible to decrement a variable daily.

Already this var (int) will be in the Shared Preferences, and every day we decrements of -1.

How could I decrement, knowing that the user does not necessarily open the app every day for example?

Have a good day :)

Answer Source

You have several choices:

  1. Every time your app starts, load the value from Shared Preferences and decrement it by the number of days which have passed.

  2. Write a service which decrements the values every day.

  3. Write a BroadcastReceiver which starts when the date changes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download