Answer the question
In order to leave comments, you need to log in
How to put a timer on a button in Android Studio?
There is a button, it is necessary that by pressing the button it becomes inactive (setEnabled (false)) and remains so for five hours, after five hours the button becomes active again.
I know how to make it inactive, but I don’t understand how to make a timer so that (the button) becomes active after 5 hours and that the button remains inactive for these five hours even if the application is closed.
Answer the question
In order to leave comments, you need to log in
1. When you click on the button, you need to save the timestamp somewhere (in the database, in Preferences).
2. When opening a screen with this button, compare the current time with the saved timestamp - if 5 hours have passed, the button is created on the screen as active, if not - the button is created inactive.
3. To activate the button at the right time with a constantly open screen with this button, you need to use some kind of timer implementation. Start the timer when the screen is opened (onResume) for the time that must pass from the current moment to the saved timestamp + 5 hours and stop when the screen is closed (onPause). When the timer has run out, the button is activated.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question