For an android app, i want start three services using firebase job dispatcher on different days. Can I use same FirebaseDispatcher object for all the three jobs?. Meanwhile, How to maintain same FirebaseDispatcher object even though app is closed?. If i use static object it will be cleared if app crashes. So how to maintain my FirebaseDispatcher object for scheduling multiple services using same dispatcher object? or Can I create different FirebaseDispatcher object for different services? Is it good practice?
Asked
Active
Viewed 605 times
1 Answers
1
- You can use the same FirebaseJobDispatcher for all Jobs.
- When the application is closed, your Jobs will be executed. How? This is the Android OS concern.
- You simply describe when and how your Jobs will be launched. It's all. Read the documentation again and see the comments in the source code of the library.
- You can create the new FirebaseJobDispatcher for different Jobs.
- Misapplication of static objects -- is bad practice.
So
FirebaseJobDispatcher dispatcher1 =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job job1 = dispatcher1.newJobBuilder()
.setService(YourService1.class)
.setTag(Const.JOB_TAG_1)
// more options to run
.build();
Job job2 = dispatcher1.newJobBuilder()
.setService(YourService2.class)
.setTag(Const.JOB_TAG_2)
// ...
.build();
dispatcher1.mustSchedule(job1);
FirebaseJobDispatcher dispatcher2 =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
dispatcher2.mustSchedule(job2);
dispatcher1.cancel(Const.JOB_TAG_1);
dispatcher2.cancel(Const.JOB_TAG_2);

tim4dev
- 2,846
- 2
- 24
- 30
-
Thanks for your help. – sathish Oct 17 '17 at 08:38