android-priority-jobqueue icon indicating copy to clipboard operation
android-priority-jobqueue copied to clipboard

Update GCMNetworkManager to Firebase Job Dispatcher

Open LouisCAD opened this issue 9 years ago • 17 comments
trafficstars

Hi!

After reading the GcmNetworkManager docs, I saw something written in red here, at the bottom of the page which says:

When Google Play Services or the client app is updated, all scheduled tasks are removed. GcmNetworkManager invokes the client app’s onInitializeTasks(). Override this function to reschedule necessary tasks.

I looked at the source code (in v2alpha4), and saw that the onInitializeTasks() is NOT overriden, so this means that each time Google pushes an update to Google Play Services, which happens all the time, and each time I publish a newer version of my app, my app will wait until the user starts it again to run the JobManager because it's not rescheduled, right?

If I'm not wrong, can you properly override this method in the library please?

It doesn't seems there's something similar with the framework's implementation, JobScheduler though.

EDIT:

GCMNetworkManager is fading away, letting Firebase Job Dispatcher replace it. This new version seems to no longer require rescheduling after Play Services or app update, but this library needs to use it to benefit from it.

LouisCAD avatar Jun 22 '16 08:06 LouisCAD

We don't have any code to do this work yet but can be added. I'll consider adding this but probably post 2.0.

yigit avatar Jun 23 '16 02:06 yigit

How to make sure Jobs are rescheduled in the meantime? Is it that complicated to add before v2 is out of alpha? I mean, isn't this just about calling the same code that scheduled the tasks initially, i.e. a copy/paste or a method call?

LouisCAD avatar Jun 23 '16 06:06 LouisCAD

No it is not because this will require re-querying the database to find such jobs and rescheduling for them (so it is a different logic). The jobs will still be run, is just wont be re-scheduled via the JobScheduler.

I really want to get out v2 so I have to cut somewhere and push for a stable release instead of adding new features.

yigit avatar Jun 23 '16 07:06 yigit

I see, and agree, get a stable v2 out has a higher priority. Thanks!

LouisCAD avatar Jun 23 '16 08:06 LouisCAD

Congrats for v2 release!

So this will now be addressed soon, right? I guess there's some things to take into account: At last Google I/O (2016), some Google services which included GCM got a rebranding, and some API changes too. For GCMNetworkManager, it seems that Firebase Job Dispatcher is now the way to go. Although it means your library will need refactoring to support it, it seems like rescheduling is not needed anymore now, so maybe this issue should be renamed to "Update to Firebase Job Dispatcher"?

LouisCAD avatar Aug 17 '16 07:08 LouisCAD

yea i need to do that :/. Meanwhile, you can probably copy GCM code and make it work for Firebase dispatcher. JobManager only uses a scheduler API so it is generic.

yigit avatar Aug 18 '16 15:08 yigit

So I edited the name of this issue. I don't need it ASAP, so I'll wait for it to be officially part of this library, though, so no need to worry or hurry.

LouisCAD avatar Aug 18 '16 16:08 LouisCAD

This would be great - currently trying to use this with Firebase and the firebase guide says to not use this dependency anymore with FCM compile 'com.google.android.gms:play-services-gcm:9.4.0'

riggaroo avatar Sep 13 '16 07:09 riggaroo

I guess this issue, whose Firebase guys still didn't pay any attention is blocking this one, right? EDIT: issue resolved

LouisCAD avatar Sep 14 '16 07:09 LouisCAD

I updated to FCM from GCM and now when I run the app, I get the following error:

/Users/spark/Documents/galleri5/Android/App/galleri5/app/src/main/java/com/galleri5/android/Galleri5Application.java Error:(152, 40) error: incompatible types: Class<MyGcmJobService> cannot be converted to Class<? extends GcmJobSchedulerService> /Users/spark/Documents/galleri5/Android/App/galleri5/app/src/main/java/com/galleri5/android/services/MyGcmJobService.java Error:(9, 8) error: cannot access GcmTaskService class file for com.google.android.gms.gcm.GcmTaskService not found Error:(11, 5) error: method does not override or implement a method from a supertype Error:org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.

What can I do to resolve this?

pipipzz avatar Sep 27 '16 09:09 pipipzz

@pipipzz which version of GCM are you using ? I've tried updating dependency to 10.0.1 but does not create any errors :/. I try to keep version minimal so that it picks app's version but if there is an incompatibility, i'll update.

yigit avatar Jan 15 '17 18:01 yigit

@yigit He is not using the GCM dependency but the FCM one

LouisCAD avatar Jan 15 '17 19:01 LouisCAD

But that depends on GCM: https://github.com/firebase/firebase-jobdispatcher-android/blob/master/jobdispatcher/build.gradle#L58

yigit avatar Jan 15 '17 21:01 yigit

Basically, i cannot figure out what job queue will gain by moving to firebase (besides additional dependencies). It still uses GCM behind the scenes and job queue already does that. I think i'll just go ahead and update job queue's dependency to gcm 10.

yigit avatar Jan 15 '17 21:01 yigit

@yigit Only the withGcmDep productFlavor of Firebase Job Dispatcher depends and uses GCM behind the scenes if you look closer at the build.gradle file you linked, and that version isn't even updated (still released at 0.5.0 while the latest is 0.5.2). So I think using Firebase Job Dispatcher would be useful for people that don't want to use GCM anymore as it's being replaced by FCM

LouisCAD avatar Jan 16 '17 08:01 LouisCAD

I recently moved to FCM and I am unable to compile my code because there is no GCM. Anyone who moves to FCM can no longer use this library. I guess it is time to add some FcmJobSchedulerService.

error: cannot access GcmTaskService 
public class JobQueueGCMService extends GcmJobSchedulerService {       
 ^   class file for com.google.android.gms.gcm.GcmTaskService not found |  

mwajeeh avatar Mar 19 '18 20:03 mwajeeh

@mwajeeh If your minSdkVersion > Lollipop, you can delete GcmJobSchedulerService, holding just FrameworkJobSchedulerService

ClarkXP avatar Apr 02 '19 19:04 ClarkXP