2017-11-03 3 views
1

を繰り返して、私は私が仕事を持つことができることを確認Trigger.NOWまたは0,0の時間を使って今すぐ開始:Firebase Jobdispatcher - 今起動して、この例パー

Bundle myExtrasBundle = new Bundle(); 
myExtrasBundle.putString("some_key", "some_value"); 

Job myJob = dispatcher.newJobBuilder() 
    // the JobService that will be called 
    .setService(MyJobService.class) 
    // uniquely identifies the job 
    .setTag("my-unique-tag") 
    // one-off job 
    .setRecurring(false) 
    // don't persist past a device reboot 
    .setLifetime(Lifetime.UNTIL_NEXT_BOOT) 
    // start between 0 and 60 seconds from now 
    .setTrigger(Trigger.executionWindow(0, 60)) 
    // don't overwrite an existing job with the same tag 
    .setReplaceCurrent(false) 
    // retry with exponential backoff 
    .setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL) 
    // constraints that need to be satisfied for the job to run 
    .setConstraints(
     // only run on an unmetered network 
     Constraint.ON_UNMETERED_NETWORK, 
     // only run when the device is charging 
     Constraint.DEVICE_CHARGING 
    ) 
    .setExtras(myExtrasBundle) 
    .build(); 

dispatcher.mustSchedule(myJob); 

私の質問は次のとおりです。

ジョブを今すぐ開始するように設定するにはどうすればいいですか?[時間間隔](それは15分と呼ぶことができます)

.setRecurring(true) //true mean repeat it 
.setTrigger(Trigger.executionWindow(start, end)) 

start:あなたの仕事の繰り返しは、定期的にこれらの2つのメソッドを呼び出すようにするに

+0

AlarmManagerを使用して15分おきにこのタスクを起動してください – Fakher

+0

私たちは実際にアラームマネージャー – Psest328

答えて

0

は、ジョブを実行する資格を考慮しなければならない(秒)最も早い時間でwindowStart、として知られています。ジョブがスケジュールされたとき(新しいジョブの場合)から計算されます。

end:windowEndとして知られています。理想的な世界でジョブを実行する最新の時間(秒)。 windowStartと同じ方法で計算されます。

+0

から離れています。しかし、15分に設定したら、今すぐ起動して15分ごとに繰り返す方法はありますか?そのままですが、初めて実行するまで15分待機します – Psest328

+0

executionWindow(0、0)でAlarmManagerで始まり、15分後にexecutionWindow(0,15)で定期的なジョブを作成する非定期ジョブを作成します。 – Fakher

関連する問題