0

I would like my application to do an action after a certain amount of time has elapsed (preferablely while the app isn't open or paused).

Example:

If(hours4 == elapsed){

    this.close();
}
Serafins
  • 1,237
  • 1
  • 17
  • 36

2 Answers2

1

Use AlarmManager to schedule events to run at a future time.

Kuffs
  • 35,581
  • 10
  • 79
  • 92
0

It's quite simple. You have to start this task in background using Service. To make delay you can use AlarmManager. Here is example

or handler

new Handler().postDelayed(new Runnable() {

    public void run() {
        Intent intent = new Intent("INTENT_WAKEUP_B");
                        intent.putExtra("EXTRA_MESSAGE",message);
                        sendBroadcast(intent);
    }
}, timeToWait * 1000); // * 1000 if timeToWait is in seconds
Community
  • 1
  • 1
Serafins
  • 1,237
  • 1
  • 17
  • 36