Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android checking if app has been opened multiple days in a row

Tags:

date

android

I am trying to implement a feature which detects if the user has been on the app for 2, 3, 4.... days in a row. I am trying to think about how this would work but I am struggling, hence I need help.

Originally, I thought about getting the date, adding that to an array and then checking the last few entries of the array were in a row. For example [28, 29, 30]. This would return a message of value saying the user had visited the app 3 days in a row. The issue with this is when I overlap and go into a new month. For example [38, 29, 30, 1]. My solution will no longer work.

I am looking for a solution which gets around this problem.

Thanks in advance.

like image 313
Calum Templeton Avatar asked Oct 15 '25 17:10

Calum Templeton


1 Answers

Why don't you just store the counter -- number of days the program was opened so far and the date of last opening?

For example: At the start counter = 0; You increase it by 1 and save the current date as 'date of last launch'.

On the next opening you just compare current date with the stored one. If they are the same, you don't need to do anything (app was opened twice during a day), if the difference is 1 day, you just increment the counter and store new date, assuming app was opened 'counter' days in a row already + today. And if the difference is more than one, it means user has skipped at least one day, so you just need to make the counter = 1 again(current launch of the app) and store current date(starting brand new cycle).

like image 128
John Cvelth Avatar answered Oct 18 '25 08:10

John Cvelth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!