In my app I would like that a certain method of mine (call it toSched) will run at a given time in the future (I’m using Timestamp for knowing when).
How can this be done, and is it possible to do it even if the phone is turned off (assume there is enough battery) ?
*I know I should use AlarmManager but I’m not sure how
You want to use the Android Alarm Manager. You do it by creating a PendingIntent (which is what you want to run) and then calling the set method. Checkout this stackoverflow post for more info.
What most people do is create a PendingIntent that is a broadcast. Then they create a broadcast receiver to receive that broadcast and do what ever is supposed to be done. Here’s an example of “calling a method” to start an activity. But you can just put your own arbitrary code in the receiver to do what ever random task.