Reputation: 95
hello everyone and thank you in advance. My problem is that I have an app that the user will start in the foreground and will set a variable as a timer. The user will most likely close that app, or the phone will go to sleep. So I need the app to background and then run code to send a notification when that timer hits 0.
For the timer I would use unix time and have the background process check to see if it matched or the current time surpassed when the timer goes off.
I would like to know - A) how to send the app to the background with these instructions B) how to then foreground the app, or at least be able to send a notification after running some code
Again, thank you very much, let me know if I was not clear or if I missed someone's previous thread.
Upvotes: 2
Views: 3445
Reputation: 80
Look at extending the Android Handler class to create a custom Handler that creates a notification when the Handler receives a Message that you send it using the method sendMessageAtTime(android.os.Message, long uptimeMillis)
or sendMessageDelayed(android.os.Message, long delayMillis)
. When that timer went off could be specified using the long
parameter of either of those methods.
Hope this helped!
Upvotes: 1
Reputation: 249
This post should be a good place to start, it looks like what you want to use is a service.
How to run an android app in background?
Upvotes: 1