Android studio, unlocks the activity everyday after a given time - android

I have this quiz, when user take the quiz I get the created_at time and I want it to be available after the same time tomorrow until then it should be locked. How do I schedule the task? Can anyone give me a hand?

You can manage it using server time. So you use a scheduler and check the server time and set your logic.

Related

How to execute a request at a specific time every day?

Let's assume that I am developing an application that allows me to monitor the psychological state of a person every day. When a user completes another survey, the data for the day is saved to the database.
But if the user has not completed the survey during the day, the result Day(0, 0, 0) should be sent to the database
The question is How to implement a behavior so that at a certain time (11:59 pm) the application checks whether something is in the database for that day or not? What should i use to implement this behavior?
Thanks in advance.
You can use Work Manager to do periodic work.
check out this approved answer https://stackoverflow.com/a/51330829/7209822

How to auto-save a form on Android - Best practices

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

How to make your app do something even when you're not doing anything or even using it

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

Best way to Check remote database after fix time interval

I want to develop this simple instant messenger application. Now i can send text to database. Now i want to show a notification to the user if he receives a new message.For that i think i want to check the remote database after fix time i.e every 20 sec. What is the best way of doing that??
I know my question could end up being lame and this might not be the best technique to show user notification of new message but for now i just know that so i am implementing it . .
Suggestions are always welcome . .
Use a timer in a service, so it can occur even if the app is not in the foreground. As an aside, I wouldn't do it every 20s- far too often, if you got a significant user base it would cost you a lot of bandwidth. Back it off to less frequent- every 60 seconds is probably sufficient.

Android Alarm Reminder

I have an app which is loading upcoming dates (like Birthdays) from an SQLite database
and showing it on a ListView. That works fine.
What I now want is to inform the user regular by an Alarm or Toast or something without
starting the application. The user has the only option when to inform: on the same day or 1 day before and the time!
Has someone an idea how to realize this? Maybe a Service or a Timer, or both?
I would be very pleased about some tips.
Take a look onto AlarmManager. Also note that the service doesn't persist alarms between sessions so you'll need to re-setup them after device boot. Another option may be using Google calendar API to create birthday events, notification will be handled by Google calendar app then.

Categories

Resources