0

저는 firebase 작업 디스패처를 사용하고 있으며 인터넷 연결이있을 때마다 매분마다 실행해야하는 간단한 주기적 작업을 프로그래밍하고 있습니다. 배터리 수명을 향상시키고 다른 응용 프로그램도 작동시킬 수 있지만 지연 시간이 너무 길기 때문에 작업이 정시에 실행되지 않는다는 것을 알고 있습니다. 그것은 원하는 1 분에 비해 너무 길어서 25 분에 도달 할 수 있습니다. 정기 작업을 적어도 매 3-5 분마다 실행하도록하는 방법이 있습니까?주기적인 작업의 지연을 줄이는 방법이 있습니까?

Thix 내가 주기적 작업 프로그래밍하는 방법이다 : 당신이 원하는 경우

FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(MainActivity.this)); 

     Job myJob = dispatcher.newJobBuilder() 

       // the JobService that will be called 
       .setService(MyJobService.class) 
       // uniquely identifies the job 
       .setTag("my-unique-tag") 
       .setRecurring(true) 
       .setLifetime(Lifetime.FOREVER) 
       // start between 0 and 10 seconds from now 
       .setTrigger(Trigger.executionWindow(0, 10)) 
       .setReplaceCurrent(true) 
       .setRetryStrategy(RetryStrategy.DEFAULT_LINEAR) 
       // constraints that need to be satisfied for the job to run 
       .setConstraints(
         // only run on an unmetered network 
         Constraint.ON_UNMETERED_NETWORK 
       ) 
       .build(); 

     dispatcher.mustSchedule(myJob); 

답변

0

당신의 MyJobService이를 변경해야하는 모든 분 ...

.setTrigger(Trigger.executionWindow(0, 10)) 

를 실행하려면 ...에 이 ...

.setTrigger(Trigger.executionWindow(60, 60)) 

이전에 들었던 내용은 전화 번호 FirebaseJobDispatcher으로 0-10 초마다 작업을 시작하십시오. 60,60 창을 띄우면 약 60 초마다 작업이 시작됩니다. 이것을 55,65 또는 다른 변형으로 변경할 수도 있지만 60,60은 저에게 유용합니다.

관련 문제