我在一个活动上创建了静态方法来调用作业调度程序 Jobdispatcher 不会调度作业,我猜。请帮忙。
Add.java 类中的方法
public void add_details(String namel,String descl,String timel)
{
add_job(timel);
}
synchronized public void add_job(String time)
{
Driver driver = new GooglePlayDriver(Add.this);
FirebaseJobDispatcher firebaseJobDispatcher = new FirebaseJobDispatcher(driver);
Job job = firebaseJobDispatcher.newJobBuilder()
.setService(Addition_job.class)
.setTag(JOB_TAG)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(5,30))
.build();
firebaseJobDispatcher.mustSchedule(job);
}
Addition_job.class
public class Addition_job extends JobService{
private AsyncTask Task;
@Override
public boolean onStartJob(JobParameters job) {
Task=new AsyncTask() {
@Override
protected Object doInBackground(Object[] params) {
Context context=Addition_job.this;
Decision.notify_user(context);
return null;
}
};
return true;
}
@Override
public boolean onStopJob(JobParameters job) {
if (Task != null) Task.cancel(true);
return true;
}
}
Decision.java notify_user 方法
public static void notify_user(Context context)
{
if(context!=null)
Toast.makeText(context,"notified:",Toast.LENGTH_SHORT).show();
}
我已经在清单中使用export=false
和指定了服务action_Execute
。