How to reset a value after 24 hour passed in android - java

I want make a kind of a daily login reward.
I have a button named ClaimReward and A user can claim reward one time in a day!. if user claimed the reward then disable the button and if
24 hours passed then again enabled the button.
My try
I stored a today's date in firebase realtime database in millis (long) or timestamp - 1353534920
So, how can I do this in android

You can get this output with this logic.
Store the value you want to reset to the preset value using shared preferences
Store the date-time value from the system using the sharedPrefs.
On App startup check if the local time matches the time in sharedPrefereces.
If it matches -> do nothing
if it does not -> reset
PS: Here shared preferences is just an example you can use room/datastore or anything to perform this check on app startup.

Related

Deleting firebase data after 'n' days but in reference to server time

I want to do similar things like in this post:
How to delete firebase data after "n" days
But the solution given there allows user to delete everything from database by changing the date on his phone.
How to deleting firebase data after 'n' days but not in reference to the time set by the user.
Where can I get "a safe time" which couldn't be changed by the user of app?

android, Everyone should evaluate each day only once

I'm going to build an app. Until now everything runs very well. Now I have a problem. The app gets its content from a mysql database.A column is called item.I have a ratingbar. The user can rate the item there.Every time the user evaluates an item the value is stored on the database in the respective item line.The values ​​are then added. In other words, when a user evaluates 20 times with 5 stars, the value adds up to 100 and so on.
I want to limit this. I will that the user can evaluate each day only once an item. I will it without a registration mask for the user. How can I solve this problem?
I know that i can identifier the WIFI MAC Adreess and other Unique Identifiers, but how can i solve this with them?
I can not use sqlite database, because the items should update with the time from the mysql database.
A registration mask should not be excluded. If this process is quite possible with them, then I supplement it with it.
I am looking forward to every comment
every computer has a machine ID, you will hash that and encrypt that to use as your identifier..most telecomms do not like using MAc addresses as IDs
One option would be to create UUID during every installation and sending this UUID to your server along with every request. In server, you can control very well if user can provide feedback once a day or others based on your requirement. Pls refer this link on how to create UUID.
https://developer.android.com/reference/java/util/UUID.html

mysql compare 2 dates

I'm absolute noob in Java and Mysql. Have an assignment to make where user need to login and register. All code been done. But there is one little part where the user's login should expire in 6 month. I'm trying to accomplish it by using SELECT DATEDIFF(month,'2014-06-05','2014-08-05') AS DiffDate. I can track user's registry date but with the second date I'm a bit stumped. How can I track the current time of user login. Any suggestions. Thank you.
You can use MySQL NOW() :
SELECT DATEDIFF(month,'2014-06-05',NOW()) AS DiffDate

How should I go about saving/restoring progressBar?

My app is mainly a timer that counts down from 20 hours.
I am wondering which method I should use for saving the information necessary for resuming the app with the timer showing the correct value.
I don't know if I should use savedInstanceState or SharedPreferences?
My plan of action is to:
1. create a TimeStamp on the "Timer Start" button
2. save the TimeStamp variable with either the savedInstanceState or SharedPreferences
3. When app is closed and re-opened, get the TimeStamp variable
4. change progressBar status to display the correct remaining time based on the TimeStamp instead of restarting the progressBar from 0.
You should go with shared preferences. Shared preferences are designed to hold persistent state while saved instance state is mainly designed for restarting an activity after configuration changes.
See Google Developer Activity JavaDoc page

to enter a time to sqlite database using java which doesnot exist in the database before

I am using java and sqlite as back end my requirement is I have to enter a time to the database,i have 2 fields starttime and endtime in database and while registering i have to check whether that time slot is already used by another user ?
I guess for that first you have to calculate EndTime-StartTime=RequiredSlot
Then you have to run query on database to check if RequiredSlot is assign to anyone else.
Considering Same Date..

Categories

Resources