2

I want to create an app that daily notifies me a value on a web page, I found this answer. It says that JobScheduler will do the trick for the daily part but I am not sure if it is going to run when the app is closed.

By the way I found that if I want to run a job every 3 seconds the code will be the following:

JobInfo.Builder builder = new JobInfo.Builder(1,
            new ComponentName(getPackageName(),
                    JobSchedulerService.class.getName()));
builder.setPeriodic(3000);

If it is daily, should the time be:

builder.setPeriodic(86400000);

Or is there any way to Schedule at a exact time e.g. 9:00 a.m.

2 Answers2

1

Unless your app has been force closed, any job scheduled with job scheduler will run even if the app is terminated. If needed it will be restarted. The only thing that will prevent it is if you declare the job not persistent and reboot the device.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
0

Try to use AlarmManager. You can find example here.

Marcin Armatys
  • 599
  • 9
  • 25