来自 Firebase JobDispatcher 文档Firebase JobDispatcher
setTrigger(Trigger.executionWindow(0, 60))
// start between 0 and 60 seconds
但为什么我的服务运行两次
Firebase JobDispacther 代码
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
Job job = dispatcher.newJobBuilder()
.setTag("testing job")
.setService(TestingJob.class)
.setReplaceCurrent(true)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(0,1))
.setConstraints(Constraint.ON_ANY_NETWORK)
.setLifetime(Lifetime.FOREVER)
.build();
dispatcher.mustSchedule(job);
测试类(就业服务)
public class TestingJob extends JobService {
private static final String TAG = "TestingJob";
private int i =0;
@Override
public boolean onStartJob(JobParameters job) {
Log.d(TAG, "onStartJob Testing Job: "+new Date().toString());
Log.d(TAG, "onStartJob: i = "+String.valueOf(i));
i+=1;
return false;
}
@Override
public boolean onStopJob(JobParameters job) {
Log.d(TAG, "onStopJob Testing Job: Stopped");
return false;
}
}
原木猫
11-28 00:08:57.666 11793-11793: onStartJob Testing Job: Tue Nov 28 00:08:57 GMT+05:00 2017
11-28 00:08:57.666 11793-11793: onStartJob: i = 0
11-28 00:08:57.791 11793-11793: onStartJob Testing Job: Tue Nov 28 00:08:57 GMT+05:00 2017
11-28 00:08:57.791 11793-11793: onStartJob: i = 0
显现
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<service android:name=".services.TestingJob"
android:exported="false">
<intent-filter>
<action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/>
</intent-filter>
</service>
我可以再次使用我的工作服务意味着int i
每次都应该增加。
感谢您的帮助