Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am developing one mobile app where I have to show one tip per day if user clicks on the tip button. all the tips are defined in one text file. It reads the file and randomly pics up the tip (using Random of Java) and displays in the app.
Now my question is how can I restrict the app to show one tip per day. Tip should be same for the whole day doesn't matter how many times user clicks on tip button in the app.
Please provide your ideas to make it work.
I would use a daily alarm to store the tip of the day in the shared preference of the android device. Then you can retrieve the tip of the day from the shared preference and not worry about anything else.
Shared preference
Alarm
maybe use System.currentTimeMillis() and map this timestamp to some picking method? maybe basing on day number in month, week or even year?
Calendar cal = Calendar.getInstance();
//by default it gets current time
//you might set another using setTimeInMillis(long milliseconds)
int dayNum = cal.get(Calendar.DAY_OF_YEAR);
String[] tips = ... ;
int posOfTip=tips[dayNum%tips.length];
String yourTip = tips[posOfTip];
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
is there a way to make the user add just one item per day, then get an alert saying "only one time a day"
what to use, coroutine, tasktimer, work manger ?
I will try and give a general answer.
Usually when it comes to such requirements it is good to compare the date and time of the last item that was created and the current date and time. That means you would need to store the item in a database.
The reason I'm suggesting such an approach is because a user might close your app, or the OS might put it to sleep / terminate it and all of your tasks and timers might be stopped. By having it persisted in a DB, you can always be sure your requirements are met.
For example if the requirement is 24 hours or perhaps just a calendar day (after midnight), then you would do the comparison and know if they have been met and allow the creation of new items, or not.
Additionally, it's always good to try and experiment at first. See what works and what doesn't before asking your question.
Good luck.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a problem that I'm stuck at, I'm trying to create a countdown timer that update itself from firebase, the timer will be shown to all users whenever a user visit my app ( I am creating a school management application,I want the timer the countdown timer to look like this 12days: 32 min : 3second to exams and let it automatically refresh so that it get new content).
I think the easiest way to do this is to create a deadline date value and store that date value in a firebase databse. When the user opens the app, you fetch the deadline value from firebase and then start a count down timer in the local app.
To get the deadline value from firebase you can use this link.
To create a count down timer you can use this link.
What you can do instead of changing the timer from Firebase is to save a timestamp into Firebase (the date you are planning to countdown from) and then query it client side and do the calculations of the days from the client.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm starting to build an app where people vote certain stuff just by clicking on happy/sad faces (kind of like grading it). The thing is that I dont want to make a log-in nor registration for my app (the reason is a long story). So is there any way that I can limit people's vote to 2 per day? Every phone/user could only vote twice a day, and that count will reset after 24h from the first vote.
You have tow options:
Limit the number of votes on the device, by saving the number of votes into persistant storage on the device with a timestamp and act accordingly.
Or (more secure, but also more difficult)
Track the installations as described here identifying app installation
And send the id with every request and validate on the server side.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am developing a website where the users will add items they want to sell.
I am now trying to figure out a way how to place a munite counter for every newly added item. I need the counter to start from 0 and count every minute the item has been active. I also need the counter to reset at the end of every month and start again from 0 in the beginning of the next month.
Do you have any suggestions where I can start from?
I will appreciate any help here.
Thanks a lot!
If I were you I would store the creation date inside a database and derive the number of minutes it has been available from it. If you're going to store a counter in memory things won't scale, apart from the fact that in case of failure you would lose all information.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I want to do a running trainer app. For some of the things that I do I need to know when a day has passed, meaning the date has changed(at 24:00).
Here are some options:
Of course I can always check if the current time is smaller then 24:00, which is not efficient.
Also I saw that I can use intent filter - ACTION_DATE_CHANGED - and along with a broadcast receiver which will listen to this intent i will know when the date has changed.
However I think that this is not the most efficient way because its always listen and probably will take some battery and CPU. Android probably did a good job in making broadcast receivers efficient, however I am still wonder whether it's appropriate for my needs.
Use an alarm manager?
Which is best, or is there a different way? What do you suggest and why?
If you need to take an action each time it is 00:00 you have to use an AlarmManager and a BroadcastReceiver. Then you'll be able to do whatever you have to do inside the onReceive() method of the receiver. Oh and by the way, BroadcastReceivers are the most efficient way to do this, as they keep the device active only during the onReceive() method.
Use the AlarmManager to set a repeating call to onReceive each day at 00:00. If you need an example tell me in the comments.
Other than that, if you don't have to take any action once a day has passed, you can simply check inside the app itself. You can always save the last time your app was opened into SharedPreferences.