Search code examples
javaandroidsharedpreferencescounterandroid-savedstate

How to implement a daily streak counter in android java?


I want to implement a daily streak counter for the user. The streak count should increase by 1 if the user return t the app the next day, and the streak count should be again return to 1 if the user has not returned to the app the next consecutive day.

So far, i have tried implementing this using the given method in the image, but my daily streak always show 1. I think this is because it is never going to the 'else' part.

Can you guys help me solve this thing.Any type of help is really appreciated.

enter image description here


Solution

  • I got what i wanted using this:

    if(getSharedPreferences(SHARED_PREF_TIME, MODE_PRIVATE).getInt(STREAKS,0)==0){

    } else{

    }