【问题标题】:Does Firebase Job dispatcher needs internet access for scheduling job?Firebase 作业调度员是否需要互联网访问来安排作业?
【发布时间】:2017-09-30 20:42:12
【问题描述】:

Firebase 作业调度程序是否需要访问 Internet 才能安排作业? 当我关闭 Internet 访问时,计划的工作似乎根本没有做任何事情。当我重新打开它时,计划的作业开始工作。

这是我使用 Firebase Job 调度作业的代码。

FirebaseJobDispatcher dispatcher = 
                    new FirebaseJobDispatcher(new GooglePlayDriver(this));
Job myJob = dispatcher.newJobBuilder()
   .setService(MyJobService.class)
   .setRecurring(true)
   .setTrigger(Trigger.executionWindow(2, 10))
   .setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
   .setTag("location-update-job")
   .setLifetime(Lifetime.FOREVER)
   .setConstraints(Constraint.ON_ANY_NETWORK)
   .setRecurring(true)
   .build();

dispatcher.mustSchedule(myJob);

【问题讨论】:

  • 如果要去掉.setRecurring(true),输入两次

标签: android firebase firebase-job-dispatcher


【解决方案1】:

当你使用.setConstraints(Constraint.ON_ANY_NETWORK)时,当有任何类型的网络连接时,作业将被执行,你可以在无、任意和不计量(Wifi)之间进行选择,默认为NONE,所以只需删除setConstraints

【讨论】:

  • 感谢您提供正确的解决方案。这就是我一直在寻找的答案。
  • 如果 Internet 不可用,并且我选择了 Constraint.ON_ANY_NETWORK,作业会执行吗?还是只有在互联网可用时才会执行?
  • 它不会被执行,一旦你连接了第一个作业就会运行
猜你喜欢
  • 1970-01-01
  • 2018-04-25
  • 2017-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-25
  • 1970-01-01
相关资源
最近更新 更多