Android-job: Need help to set time!

Created on 4 Nov 2016  路  4Comments  路  Source: evernote/android-job

Hi,
I want to start a task at 9 am (exact time) at every day by using this library. Can you help me by,

  1. What is the best ( periodic or exact that is scheduled again) to start in time alarm?

  2. Then What would be the time calculation. Please give an example by my time like 9 am for each day.

Thanks,
Ruhul

help wanted

All 4 comments

A sample is here.

   Calendar calendar = Calendar.getInstance();
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    int minute = calendar.get(Calendar.MINUTE);

    int minutesToStart = 00;
    int hoursToStart = 9;

   long startMs = TimeUnit.MINUTES.toMillis((minutesToStart - (minute))) +         TimeUnit.HOURS.toMillis(((hoursToStart - hour) % 24));
    if (startMs < 0) {
        Log.d(TAG, "next scheduling in a day...");
        startMs += TimeUnit.DAYS.toMillis(1);
    }
   new JobRequest.Builder(DemoSyncJob.TAG)
            .setExact(startMs)
            .setPersisted(true)
            .setUpdateCurrent(true)
            .build()
            .schedule();

Is it ok for firing alarm at 9am and every day ??

it is not worked for me :(

I gave you a sample and you should be able to do the rest. If not, please ask these questions at a better place like Stackoverflow.

Was this page helpful?
0 / 5 - 0 ratings