Как из Firebase JobDispatcher Documentation Firebase JobDispatcher
setTrigger(Trigger.executionWindow(0, 60))
// start between 0 and 60 seconds
, но почему мой сеанс работает два раза
Firebase JobDispacther Code
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;
}
}
Журнал Cat
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>
Могу ли я использовать сервис Job Service снова, значение int i
должно увеличиваться каждый раз.
Thnx для вашей помощи