Logic:
What:
1. When ever you show the toast, Save the date/day in sharedPreferences.
2. Then each time, compare the value of "today's date" with the sharedPref value, if its different, show the toast.
How:
- Make a function for the toast, inside which update the Shared Pref value.
- In an "if" loop, compare the default shared pref value - so when you run the app for the first time, it'l return the default value and enter the show toast function.
Eg.
if(!(sharedPrefSavedDate.equals(sharedPrefDefaultValue))){
if(!(String.valueOf(new SimpleDateFormat("dd").format(new java.util.Date())).equals(sharedPrefSavedDate)){
showToast();
}
}
Inside showToast()
, save the value of today's date in Shared Preferences.
The saved value can be integer or String. Can change .equals
to !=
of =
accordingly.
May require:
How to use shared preferences
Example with integer on android developers