My question might be bit confusing, but what I basically want to do is,
I want to display the time exceeded for each item in the list when the start button on each item is clicked.
For example, suppose I have a listView of items that has a time and a button
TIME START
TIME START
TIME START
When I click the start button, the TIME textView should start a timer that increments every 1 minute and stops when it reaches a specific minute).
Since I am using the Firebase realtime database as my DB, I was thinking of incrementing 1 to the Time data every 1 minute.
What is a good approach of doing this?
You can update a value in Firebase Realtime Database either on client side or either on server side by using Cloud Functions for Firebase.
You can write a function that updates that particular value every 10 minutes. The benefit of using Cloud Functions rather then the first option is that will still work even if the application is offline. This is the best practice.
Related
I am trying to introduce auto-save functionality on one of my Android applications. The idea is that as the user inputs first name, last name and after a fixed interval I would like to save that information to the server before the user hits Next button. The final goal is to have something similar to the draft option in the Gmail app where your email information is automatically saved. So, if there is a timer that runs every 10 seconds, I will pass the information on the screen to the ViewModel and let it deal with the logic of saving the data to the server.
A couple of options I have explored are.
Execute recurring code with a specified interval using Handler.
PeriodicWorkRequest -- however this option has a minimum interval of 15 minutes which is a little too much for my use case.
AlarmManager -- This option runs even if your application is not currently running, In my opinion, this option can be an overkill.
I wanted to know if there are best practices/blogs around this and if anyone I on the wrong path or potential red flags with this approach.
you can make countdown for 10 second, when countdown is down save the data and call the countdown again.
when your activity is destroyed, so stop the countdown
I am developing android application on which peoples donate food etc and when they submit their donations i want to start timer about 30 to 50 minutes in background even they close the application. Timer continuously run in background and if any user open the app it shows the remaining time also according to background progress.
I want to use background service which count time but if any user submitted multiple orders then how it works and also I want to change time duration through firebase. Background time is running and if we decide to increase time then we increase it through firebase and changes also takes place in app background service.
What are they ways I used to implement this kind functionality.
Do you want any notification from background ? If not, you don't need a background service just to display remaining time.
All you have to do is :
save the time of the last donation in SharedPreferences for example or in Database
every time the app is opened
check the duration with Firebase
launch a CountDown timer to display remaining time
I think it will do the job.
I am developing an app using Android & Firebase Realtime Database where users join a room, then when the host presses start game, all clients start the main game Activity (through a ValueEventListener on a "Started" child node in the room). The main game has a 60sec countdown where users make a sentence then at the end of the 60secs all sentences are collected and displayed.
I am having a hard time collecting all of the sentences at the end due to the 60sec timers being so off on different clients. I need a way to ensure all games end at the same time so the collection process is smooth and nothing gets missed.
I know that Firebase has both: /.info/serverTimeOffset and ServerValue.TIMESTAMP but i'm struggling on how to use them to sync timers.
I have tried to use System.currentTimeMillis() + serverTimeOffset to estimate the server time and get all clients to count down to endTime - (System.currenTimeMillis() + serverTimeOffset) where endTime is a time written to the database by the host that all clients read but timers are still way off.
What is the best way to handle this situation?
I would suggest:
Instead of running a timer that updates every second on the server, simply store the start/stop times of the event and allow the clients to manage their own timers.
Not be done by -1 every second (as setInterval and other client-side tools are not very exact) but by comparing the current timestamp to the end, and determining the difference.
This question is vague but I am not sure what to Google for exactly.
But in my app I have a section where you create a list of tasks with various attributes, and a lot of these numbers are summed up and displayed in daily totals visually. But these daily totals should reset every 24 hours (based on the hour of the day the user chooses for the cutoff, e.g. 3 am if someone works late).
Right now: my database can hold all the data by day. Then my daily counters will visually display the numbers by pulling the corresponding data from the database looking for the current day. That's the easy part.
The hard part: I can refresh the counter after the time cutoff if the user rotates the screen or restarts the app because then it'll be looking for items in the database with a new day that won't be found, so everything will be 0 as intended. But what if the user is just staring at the screen as the time cutoff rolls by? How do I make the app refresh the counters once the time hits? What if they're not even using the app at all (either it's minimized in the background or not even active).
Do I need to have some kind of always-running loop in the background that checks the current time against the values in the database? If so, isn't this inefficient if it's always needing to pull values from a database based on time? What's the correct practice for something like this?
You can setup a service and schedule that service to run periodically so that it does whatever job you want it to do
maybe this article can help you.
Alarm manager and services will be ideal for you to implement to do something for your requirement.
Services : It will be running all the time irrespective of your life-cycle of activity.
Alarm manager: Inside services use alarm manager to trigger event to update UI at regular interval.
Finally you can use Local braodcast reciever to update your Activity from services.
You can check implemetation in details below :
Android update activity UI from service
I am trying to develope android mobile app and I have bids with limited time and that time decrease if the user click on bid button for example:
if we have bid with 5 hours and if on click = 1 hour so if five users clicked the bid button then the bid should close.
The problem appear if no one bid on bid so I need to colse it after 5 hours.
So far I have sql server 2016 cloud database with two columns bid and the remaining time and the remaining time decrease by each click. but if noclick I have to check every second using cron job to check the remaining time and close once it reach zero.
I don't think the cron job is the optimal solution I tried to check the trigger time base but didn't find any in sql server.
Could you tell me the best technique to solve the problem may be a new technique to solve it from mobile prospective or sql server view?