for learning purposes, I am trying to write a simple sleep timer app. Purpose should be to have a picker, select a number of minutes and after that time, perform certain actions. Most importantly, activate flight mode and close all other applications to save the battery.
I have a custom picker and my runnable thread, which works fine:
@Override
public void run() {
while((System.currentTimeMillis() - startTime ) / 1000 < minutes){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("interrupted, go again.");
return;
}
}
System.out.println("Wait time is over, go to sleep.");
app.timeToSleep();
however, within "timeToSleep" I now want to do things like:
Device.setFlightmodeEnabled(true); or
TaskManager.killall();
How would I achieve something like that? I have not found anything so far, but maybe I have the wrong key words to look for.
Thanks and best regards