Giter Site home page Giter Site logo

firebase-jobdispatcher-android's Introduction

Firebase JobDispatcher

Status: Archived

This repository has been archived and is no longer maintained.

status: inactive


Update: April 2019

Last year, we announced Android Jetpack WorkManager. WorkManager, the new job management system in Jetpack, incorporates the features of Firebase Job Dispatcher (FJD) and Android’s JobScheduler to provide a consistent job scheduling service back to api level 14 while leveraging JobScheduler on newer devices. WorkManager works with or without Google Play Services, which is something FJD cannot do. WorkManager was first released to alpha in May 2018 and then went thru extensive iteration and improvement based on developer feedback including 10 alphas; it moved to beta on Dec 19, 2018, and was released to stable on Mar 5, 2019. One thing the team has been discussing at some length is whether it would be better for developers in the long run if we create one holistic solution via WorkManager; where we can pool all of our efforts and also give developers a single unified recommended path?

After careful evaluation, the team has decided to focus all of our efforts on WorkManager and to deprecate Firebase Job Dispatcher. We have modified our plans in direct response to developer feedback in order to make this as easy for you as possible. We know that managing background work is a critical part of your app and these changes impact you. We want to support you through this migration as much as we can by giving you as much advance notice as possible to make these changes. Firebase Job Dispatcher will be archived in github in about 1 year, on Apr 7, 2020. Apps should migrate to WorkManager or an alternative job management system before this date.

We’ve created a detailed migration guide to assist you in the transition to WorkManager. After Apr 7, 2020, this github repository will be archived and support for FJD customer issues will stop. Additionally, FJD will stop working once your app starts targeting an Android version after Android Q.

We are continuing to invest in and add new features to WorkManager and welcome any feedback or feature requests.

The Firebase JobDispatcher is a library for scheduling background jobs in your Android app. It provides a JobScheduler-compatible API that works on all recent versions of Android (API level 14+) that have Google Play services installed.

Overview

What's a JobScheduler?

The JobScheduler is an Android system service available on API levels 21 (Lollipop)+. It provides an API for scheduling units of work (represented by JobService subclasses) that will be executed in your app's process.

Why is this better than background services and listening for system broadcasts?

Running apps in the background is expensive, which is especially harmful when they're not actively doing work that's important to the user. That problem is multiplied when those background services are listening for frequently sent broadcasts (android.net.conn.CONNECTIVITY_CHANGE and android.hardware.action.NEW_PICTURE are common examples). Even worse, there's no way of specifying prerequisites for these broadcasts. Listening for CONNECTIVITY_CHANGE broadcasts does not guarantee that the device has an active network connection, only that the connection was recently changed.

In recognition of these issues, the Android framework team created the JobScheduler. This provides developers a simple way of specifying runtime constraints on their jobs. Available constraints include network type, charging state, and idle state.

This library uses the scheduling engine inside Google Play services(formerly the GCM Network Manager component) to provide a backwards compatible (back to Gingerbread) JobScheduler-like API.

This I/O presentation has more information on why background services can be harmful and what you can do about them:

Android battery and memory optimizations

There's more information on upcoming changes to Android's approach to background services on the Android developer preview page.

Requirements

The FirebaseJobDispatcher currently relies on the scheduling component in Google Play services. Because of that, it won't work on environments without Google Play services installed.

Comparison to other libraries

Library Minimum API Requires Google Play Service API1 Custom retry strategies
Framework JobScheduler 21 No JobScheduler Yes
Firebase JobDispatcher 14 Yes JobScheduler Yes
evernote/android-job 14 No2 Custom Yes
Android WorkManager3 14 No2 Custom Yes

1 Refers to the methods that need to be implemented in the Service subclass.
2 Uses AlarmManager or JobScheduler to support API levels <= 21 if Google Play services is unavailable.
3 Currently in alpha phase, soon to graduate to beta.

Getting started

Installation

Add the following to your build.gradle's dependencies section:

implementation 'com.firebase:firebase-jobdispatcher:0.8.6'

Usage

Writing a new JobService

The simplest possible JobService:

import com.firebase.jobdispatcher.JobParameters;
import com.firebase.jobdispatcher.JobService;

public class MyJobService extends JobService {
    @Override
    public boolean onStartJob(JobParameters job) {
        // Do some work here

        return false; // Answers the question: "Is there still work going on?"
    }

    @Override
    public boolean onStopJob(JobParameters job) {
        return false; // Answers the question: "Should this job be retried?"
    }
}

Adding it to the manifest

<service
    android:exported="false"
    android:name=".MyJobService">
    <intent-filter>
        <action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/>
    </intent-filter>
</service>

Creating a Dispatcher

// Create a new dispatcher using the Google Play driver.
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));

Scheduling a simple job

Job myJob = dispatcher.newJobBuilder()
    .setService(MyJobService.class) // the JobService that will be called
    .setTag("my-unique-tag")        // uniquely identifies the job
    .build();

dispatcher.mustSchedule(myJob);

Scheduling a more complex job

Bundle myExtrasBundle = new Bundle();
myExtrasBundle.putString("some_key", "some_value");

Job myJob = dispatcher.newJobBuilder()
    // the JobService that will be called
    .setService(MyJobService.class)
    // uniquely identifies the job
    .setTag("my-unique-tag")
    // one-off job
    .setRecurring(false)
    // don't persist past a device reboot
    .setLifetime(Lifetime.UNTIL_NEXT_BOOT)
    // start between 0 and 60 seconds from now
    .setTrigger(Trigger.executionWindow(0, 60))
    // don't overwrite an existing job with the same tag
    .setReplaceCurrent(false)
    // retry with exponential backoff
    .setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
    // constraints that need to be satisfied for the job to run
    .setConstraints(
        // only run on an unmetered network
        Constraint.ON_UNMETERED_NETWORK,
        // only run when the device is charging
        Constraint.DEVICE_CHARGING
    )
    .setExtras(myExtrasBundle)
    .build();

dispatcher.mustSchedule(myJob);

Cancelling a job

dispatcher.cancel("my-unique-tag");

Cancelling all jobs

dispatcher.cancelAll();

Contributing

See the CONTRIBUTING.md file.

Support

This library is actively supported by Google engineers. If you encounter any problems, please create an issue in our tracker.

License

Apache, see the LICENSE file.

firebase-jobdispatcher-android's People

Contributors

abeisgoat avatar amitdmaskery avatar ciarand avatar dgnemo avatar googolmo avatar ianhanniballake avatar janclarin avatar jhamberg avatar michaeldiener avatar sakebook avatar samtstern avatar supercilex avatar toddshansen avatar unegor avatar vrallev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

firebase-jobdispatcher-android's Issues

IllegalArgumentException: Service not registered: com.firebase.jobdispatcher.ExternalReceiver$JobServiceConnection

ExternalReceiver crashes the application attempting to unbind a Service that is no longer alive. Seen this occur a few times just after running a new build from AndroidStudio, but not always, and not consistent enough to determine that's the actual cause. But since services can be killed for various reasons, I feel like ExternalReceiver should just try-catch this and not assume the service is live.

FATAL EXCEPTION: main
    java.lang.IllegalArgumentException: Service not registered: com.firebase.jobdispatcher.ExternalReceiver$JobServiceConnection@5743276
    at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1044)
    at android.app.ContextImpl.unbindService(ContextImpl.java:1337)
    at android.content.ContextWrapper.unbindService(ContextWrapper.java:616)
    at com.firebase.jobdispatcher.ExternalReceiver.onJobFinishedMessage(ExternalReceiver.java:63)
    at com.firebase.jobdispatcher.ExternalReceiver.access$200(ExternalReceiver.java:41)
    at com.firebase.jobdispatcher.ExternalReceiver$ResponseHandler.handleMessage(ExternalReceiver.java:115)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Setting job proirity

Is there any way we can set job priority while scheduling a job? moreover is there any way we can fetch all the current pending jobs?

Add AlarmManager-based Driver for pre-L, non-Google devices

If I understood it correctly, this library only includes a Driver implementation for GcmNetworkManager, which only works on devices where Google Play Services is installed. Is it planned to add another Driver implementation that works on devices without this (on both API >= 21 using JobScheduler and on API < 21 with a different implementation using AlarmManager)? Otherwise, I don't really see a big advantage of using this library over talking to GcmNetworkManager directly.

Which thread runs my jobs ?

On which thread do my jobs run? and is it safe to run long tasks there or should i start an Intent Service ?

exported="false" is correct?

The document says:

<service
    android:exported="false"
    android:name=".MyJobService">
    <intent-filter>
        <action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/>
    </intent-filter>
</service>

Is this correct?
When I set exported="false" then the job did not execute after device rebooting.
(Of course, I set setLifeTime(LifeTime.FOREVER))
I set exported="true" then the job worked correctly after device rebooting.

Generate JavaDocs

This project doesn't have any JavaDocs, which makes it very hard to navigate this project, and isn't in line with other Android/Google APIs.

JavaDocs should be generated and hosted on developer.google.com, firebase.google.com, or GitHub Pages.

Add JobScheduler-based Driver for L+, non-Google devices

As long as Firebase JobDispatcher is a library that provides a high-level wrapper around job scheduling engines on Android I wonder whether it's possible to create a Driver implementation based on Lollipop's JobScheduler?

Firebase and Lollipop's schedulers require Job to extend from JobService and the problem is both schedulers provide their own abstract JobServices so I don't see a simple possibility to create one job and reuse it for different drivers.

JobService not executed when specified to run in non default process

Version: com.firebase:firebase-jobdispatcher:0.5.0
Android Version: 4.4.4

If the JobService is specified to execute on a different process.
Like:

<service
      android:exported="false"
      android:name="com.mydomain.myapp.MyJobService"
      android:process=":myprocess">
      <intent-filter>
          <action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/>"
      </intent-filter>
  </service>

the JobService is not executed.

The following warning message is reported:
W/FJD.ExternalReceiver: Unknown service connected

Job Scheduling:

       
       final FirebaseJobDispatcher dispatcher = 
            new FirebaseJobDispatcher(new GooglePlayDriver(this));
        final Builder builder = dispatcher.newJobBuilder();
        builder.setService(MyJobService.class);
        builder.setTag(NOW_JOB_TAG);
        builder.setLifetime(Lifetime.UNTIL_NEXT_BOOT); 
        builder.setTrigger(Trigger.NOW);
        builder.setReplaceCurrent(true);
        builder.addConstraint(Constraint.ON_ANY_NETWORK);
        final Job job = builder.build();
        final int result = dispatcher.schedule(job);

Unable to put serializable extras

The JobParameters class throws an error
JobParameters is invalid: Received value of type 'chat_message_extra' for key 'class com.example.model.ChatMessage',only the following extra parameter types are supported: Integer, Long, Double, String, and Boolean

when sending a bundle with a serializable extra while building the Job.

Is this by design? If so why, when the existing Intent and Bundle system can very well support serializing and de-serializing an object.

Documentation not very descriptive

To schedule a recurring job, for a particular time window, what exactly do the parameters in Trigger.executionWindow(int x, int y) represent?

BadParcelableException when using Proguard

This is easily avoided with a Proguard rule, so adding it to the documentation may be enough.

The issue I had was getting a BadParcelableException when using Proguard, this is the stack trace:

FATAL EXCEPTION: main
Process: com.example.app, PID: 15577
java.lang.RuntimeException: Unable to start service com.firebase.jobdispatcher.GooglePlayReceiver@c883f90 with Intent { act=com.google.android.gms.gcm.ACTION_TASK_READY cmp=com.example.app/com.firebase.jobdispatcher.GooglePlayReceiver (has extras) }: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.google.android.gms.gcm.PendingCallback
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3027)
at android.app.ActivityThread.-wrap17(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1442)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.google.android.gms.gcm.PendingCallback
at android.os.Parcel.readParcelableCreator(Parcel.java:2411)
at android.os.Parcel.readParcelable(Parcel.java:2337)
at android.os.Parcel.readValue(Parcel.java:2243)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2592)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getParcelable(Bundle.java:786)
at com.firebase.jobdispatcher.f.a(SourceFile:39)
at com.firebase.jobdispatcher.GooglePlayReceiver.a(SourceFile:114)
at com.firebase.jobdispatcher.GooglePlayReceiver.onStartCommand(SourceFile:82)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3010)
at android.app.ActivityThread.-wrap17(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1442) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

Could be related to #18

This is fixed by adding the following Proguard rule:

-keep class com.google.android.gms.** { *; }

Not able to schedule job below Lollipop version and when Google play services is not installed.

I am using firebase job dispatcher using the dependency as follows. I have an explicit dependency on gcm

compile 'com.firebase:firebase-jobdispatcher-with-gcm-dep:0.5.0'.
compile "com.google.android.gms:play-services-gcm:8.4.0"

From the documentation it states that if the device is below Lollipop and Google Play services is not available, then it will use AlarmManager instead.

2: Uses AlarmManager to support API levels <= 21 if Google Play services is unavailable.

But in one of the devices which has Android version 4.2.2 and Google Play services 7.5.62, the job never runs. It should be invoked by AlarmManager according to the documentation.

Sleep Mode and Device Screen Off issues

So far its working fine until, I lock screen the device or let the device be inactive for a while.
As soon as I open the device lock, I see the My implementation of JobService getting called regardless of the Trigger 'windowStart' and 'windowEnd' time. If the device is Active then with some inconsistency in time the My JobService gets called.

Is this behavior normal ? Because I don't have battery saver turned On in the device.

final static int periodicity = (int) TimeUnit.MINUTES.toSeconds(5);
final static int toleranceInterval = (int)TimeUnit.MINUTES.toSeconds(3);

Job myJob = dispatcher.newJobBuilder().setService(MyJobService.class)
                .setTag("location-tag")
                .setConstraints(

                    Constraint.ON_ANY_NETWORK)
                .setTrigger(Trigger.executionWindow(periodicity, periodicity + toleranceInterval))
                .setLifetime(Lifetime.FOREVER)
                .setReplaceCurrent(true)
                .build();

    int result = dispatcher.schedule(myJob);


    if(result != FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS){
        Log.e("TAG", "Failed to schedule Job in JobDispatchingEntryPoint");
    }

Update: I've tested it on Lollipop only.

Fatal Exception: java.lang.RuntimeException: android.os.DeadObjectException

Received this through crash reporting:

Fatal Exception: java.lang.RuntimeException: android.os.DeadObjectException
       at com.firebase.jobdispatcher.GooglePlayJobCallback.jobFinished(GooglePlayJobCallback.java:39)
       at com.firebase.jobdispatcher.GooglePlayReceiver.onJobFinished(GooglePlayReceiver.java:162)
       at com.firebase.jobdispatcher.ExternalReceiver.onJobFinishedMessage(ExternalReceiver.java:69)
       at com.firebase.jobdispatcher.ExternalReceiver.access$200(ExternalReceiver.java:41)
       at com.firebase.jobdispatcher.ExternalReceiver$ResponseHandler.handleMessage(ExternalReceiver.java:115)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:158)
       at android.app.ActivityThread.main(ActivityThread.java:7224)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by android.os.DeadObjectException
       at android.os.BinderProxy.transactNative(Binder.java)
       at android.os.BinderProxy.transact(Binder.java:503)
       at com.google.android.gms.gcm.INetworkTaskCallback$Stub$Proxy.taskFinished(INetworkTaskCallback.java:85)
       at com.firebase.jobdispatcher.GooglePlayJobCallback.jobFinished(GooglePlayJobCallback.java:37)
       at com.firebase.jobdispatcher.GooglePlayReceiver.onJobFinished(GooglePlayReceiver.java:162)
       at com.firebase.jobdispatcher.ExternalReceiver.onJobFinishedMessage(ExternalReceiver.java:69)
       at com.firebase.jobdispatcher.ExternalReceiver.access$200(ExternalReceiver.java:41)
       at com.firebase.jobdispatcher.ExternalReceiver$ResponseHandler.handleMessage(ExternalReceiver.java:115)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:158)
       at android.app.ActivityThread.main(ActivityThread.java:7224)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

My current theory is that this is caused because jobFinished is being called after onStopJob so will add measures to prevent this will report if this continues to happen.

For God's sake, upload to Jcenter

This issue was reported 2 months ago and you said you'll work on it ASAP. Copying the .aar makes it very complicated and produces errors. I can't believe this is Firebase. You've versed my opinion about you.

Could not get unknown property 'assembleRelease' for project

After updating Android Studio to version 2.2 and the gradle plugin to 2.2.0, I get following error:

Error:(32, 1) A problem occurred evaluating project ':jobdispatcher'.
Could not get unknown property 'assembleRelease' for project ':jobdispatcher' of type org.gradle.api.Project.

The problem is in the build.gradle file of jobdispatcher (which I've imported into my project as a gradle module):

task aar(dependsOn: assembleRelease)

What changes can I make to fix this?

Note, this issue is very similar to, but still a bit different to, that reported here.

Support Library out of date

Having a dependency on the support library means that my project now complains that there's a version inconsistency if I update to the latest version of the support library. So for the last couple weeks, I've had to leave an older version active in my code. Is the support library really necessary for this library (seems like it's mostly used for tests and annotations) - if it can be removed, that would be ideal.

Assuming that's not an option, may I request that it be updated to the latest versions as those are released?

Thanks!

Does not work with <null> extras in Bundle

When using a null extra in my Bundle for the JobBuilder I get the following Exception:

com.firebase.jobdispatcher.ValidationEnforcer$ValidationException: JobParameters is invalid: Received value of type 'locationId' for key 'null', but only the following extra parameter types are supported: Integer, Long, Double, String, and Boolean
                                                                         at com.firebase.jobdispatcher.ValidationEnforcer.ensureNoErrors(ValidationEnforcer.java:113)
                                                                         at com.firebase.jobdispatcher.ValidationEnforcer.ensureValid(ValidationEnforcer.java:89)
                                                                         at com.firebase.jobdispatcher.Job$Builder.build(Job.java:186)

This seems because com.firebase.jobdispatcher.DefaultJobValidator does not support null values in validateExtrasType, but I think it is a perfectly valid use case.

Here's the code to reproduce:

Bundle myExtrasBundle = new Bundle();
myExtrasBundle.putString("test", null);

dispatcher.newJobBuilder()
				.setService(MyService.class)
				.setTag("abc")
				.setRecurring(false)
				.setLifetime(Lifetime.FOREVER)
				.setTrigger(Trigger.executionWindow(0, 60))
				.setReplaceCurrent(true)
				.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
				.setConstraints(Constraint.ON_ANY_NETWORK)
				.setExtras(myExtrasBundle)
				.build();

SecurityException: Binder invocation to an incorrect interface

I have this exception with jobDispatcherVersion = '0.5.0' (I will check with 0.5.2)

STACK_TRACE=java.lang.SecurityException: Binder invocation to an incorrect interface
        at android.os.Parcel.readException(Parcel.java:1425)
        at android.os.Parcel.readException(Parcel.java:1379)
        at com.google.android.gms.gcm.c.a(Unknown Source)
        at com.firebase.jobdispatcher.af.a(Unknown Source)
        at com.firebase.jobdispatcher.GooglePlayReceiver.b(Unknown Source)
        at com.firebase.jobdispatcher.aa.a(Unknown Source)
        at com.firebase.jobdispatcher.aa.e(Unknown Source)
        at com.firebase.jobdispatcher.ae.handleMessage(Unknown Source)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:194)
        at android.app.ActivityThread.main(ActivityThread.java:5435)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:857)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
        at dalvik.system.NativeStart.main(Native Method)

ANDROID_VERSION=4.2.2
PHONE_MODEL=HM NOTE 1W

maybe this is Proguard related ?? this is my proguard gradle:

release {
            minifyEnabled true
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

and proguard-rules.pro

-keep class * implements android.os.Parcelable {
     public static final android.os.Parcelable$Creator *;
}
# optimize
-optimizationpasses 2
-optimizations !code/simplification/arithmetic
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses

Question about job starting reliability

Hi,

I have a problem with starting a job service.
I have a following class:

public class JobsScheduler {

    private FirebaseJobDispatcher dispatcher;

    public JobsScheduler(Context context) {
        dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
    }

    public void scheduleNetworkCheckJob(int startTime, int endTime) {
        Job myJob = dispatcher.newJobBuilder()
                .setService(NetworkCheckJobService.class)
                .setTag(NetworkCheckJobService.TAG)
                .setRecurring(false)
                .setLifetime(Lifetime.FOREVER)
                .setTrigger(Trigger.executionWindow(startTime, endTime))
                .setReplaceCurrent(true)
                .setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
                .build();

        dispatcher.mustSchedule(myJob);
    }
}

And I call scheduleNetworkCheckJob method with parameters 60 and 600 (1 and 10 minutes). And I have a problem with starting this job, because sometimes 10 minutes passed and job isn't called yet.
Am I doing something wrong?
I wanting following behaviour: I want this job to start after 1 minute and check if there is internet available or not, if no this job displays system notification.

Is there maybe any possibility to increase job priority, to start this after that 1 minute? Because sometimes it is called after 2 minutes, sometimes after 8 minutes, and sometimes it isn't called at all.

I have a Huawei P9 with Android M.

Driver Docs

Could you provide more documentation about how to create custom Driver implementations? I'm trying to follow the GooglePlayDriver and it is hard to tell what is a requirement for this library and what is part of the GooglePlayDriver specific code.

It would be helpful to have a doc that says "To make a driver, you need to make sure it does xyz."

Thanks

Issues upgrading app to Play Services 9.6.x

I upgraded my app's Google Play Services dependency to 9.6.1, but I'm getting a RuntimeException when building the app. The issue is that there are duplicate com.google.android.gms.gcmPendingCallback classes. The first is from this library while the newer one is from 9.6.1.

Is it something that anyone has come across yet, and is there an alternate solution other than upgrading the jobdispatcher's dependency?

android.os.BadParcelableException: ClassNotFoundException when unmarshalling

public static void start(Team team) {
        Bundle bundle = new Bundle();
        bundle.putParcelable(Constants.INTENT_TEAM, team);

        Job job = BaseHelper.getDispatcher().newJobBuilder()
                .setService(DownloadTeamDataJob.class)
                .setTag(team.getNumber())
                .setExtras(bundle)
                .setConstraints(Constraint.ON_ANY_NETWORK)
                .build();
    }

    @Override
    public boolean onStartJob(final JobParameters params) {
        params.getExtras().setClassLoader(Team.class.getClassLoader());
        Team team = params.getExtras().getParcelable(Constants.INTENT_TEAM); // <<Exception
    }

I've tried bundle.setClassLoader(Team.class.getClassLoader()); but that doesn't seem to work.

Casues Illegal State Exception

Including the firebase.JobDispatcher aar file as a dependency causes the following error,

Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/android/gms/gcm/PendingCallback$1;

Removing the gcm library doesn't work either

BadParcelableException: ClassNotFoundException for PendingCallback

12-19 17:25:22.014 18473-18473/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: com.supercilex.robotscouter, PID: 18473
                                                   java.lang.RuntimeException: Unable to start service com.firebase.jobdispatcher.GooglePlayReceiver@61e66f2 with Intent { act=com.google.android.gms.gcm.ACTION_TASK_READY cmp=com.supercilex.robotscouter/com.firebase.jobdispatcher.GooglePlayReceiver (has extras) }: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.google.android.gms.gcm.PendingCallback
                                                       at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3343)
                                                       at android.app.ActivityThread.-wrap21(ActivityThread.java)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1582)
                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                       at android.os.Looper.loop(Looper.java:154)
                                                       at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                    Caused by: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.google.android.gms.gcm.PendingCallback
                                                       at android.os.Parcel.readParcelableCreator(Parcel.java:2536)
                                                       at android.os.Parcel.readParcelable(Parcel.java:2462)
                                                       at android.os.Parcel.readValue(Parcel.java:2365)
                                                       at android.os.Parcel.readArrayMapInternal(Parcel.java:2732)
                                                       at android.os.BaseBundle.unparcel(BaseBundle.java:269)
                                                       at android.os.Bundle.getParcelable(Bundle.java:864)
                                                       at com.firebase.jobdispatcher.GooglePlayReceiver.a(Unknown Source)
                                                       at com.firebase.jobdispatcher.GooglePlayReceiver.onStartCommand(Unknown Source)
                                                       at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3326)
                                                       at android.app.ActivityThread.-wrap21(ActivityThread.java) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1582) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                       at android.os.Looper.loop(Looper.java:154) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:6119) 
                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Is dispatcher a singleton object?

I want to know if I initialize the dispatcher in 2 components of my app are the dispatchers in sync? I mean does both of them have the jobs I have added in different parts?

Explain how recurring works

I haven't found any information about how recurring jobs works.
When is exactly a recurring job scheduled?
If I have an executing window trigger of 10 minutes one hour in future, can I expect to be rescheduled also at a 10 minutes window one hour later than first execution finished?

Evernote library comparison is wrong

In your table you mention, that the Evernote library is only supporting a retry strategy with the JobScheduler and AlarmManager API. That's not true, you can also reschedule jobs with the GCM API. There is no difference between the APIs.

Duplicated PendingCallback

Hi, I found the problem with firebase-jobdispatcher-android. You use only one class from com.google.android.gms.gcm and you don't attach dependencies GCM to build.gradle. I have in build.gradle dependencies to GCM and when I import aar firebase-jobdispatcher-android (as you wrote in README.md) I have a problem with duplicated PendingCallback class. I cannot exclude this class beacuse this is aar. Can you help me fix it?

Provide support for a pure Java module

Please abstract this library so it can work in the context of a pure java environment.

Business logic often can (and should be) simplified in a pure java module. The concept of jobs certainly fits this criteria.

This can be done with with having a pure java "core" jobdispatcher module, and a second "android" implementation of it. Somewhat similar to how Retrofit adds RxJava support without bundling it into the core library.

GooglePlayDriver: doesn't reschedule Jobs after App is updated.

GooglePlayDriver doesn't reschedule Jobs after Google Play Services or the app is updated.

GooglePlayReceiver has check for that situation in onStartCommand, but it doesn't handle this case correctly. All Jobs should be rescheduled.

To Reproduce issue:

  1. create any recurring Job with Lifetime.FOREVER.
  2. schedule the job.
  3. install updated .apk or update Google Play Services.
  4. Job won't be called no more.

Bug: crashes when emptying EditTexts

Sample doesn't allow to clear the text of the EditText.
I wanted to know what each EditText is for, so I thought clearing it will show the hint, but it crashes.

Here's the log:

06-09 11:16:31.963 23986-23986/com.firebase.jobdispatcher.testapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.firebase.jobdispatcher.testapp, PID: 23986
java.lang.NumberFormatException: Invalid int: ""
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parseInt(Integer.java:358)
at java.lang.Integer.valueOf(Integer.java:545)
at com.firebase.jobdispatcher.testapp.JobForm.setWinStartSecondsStr(JobForm.java:43)
at com.firebase.jobdispatcher.testapp.databinding.ActivityJobFormBinding$3.onChange(ActivityJobFormBinding.java:109)
at android.databinding.adapters.TextViewBindingAdapter$1.onTextChanged(TextViewBindingAdapter.java:367)
at android.widget.TextView.sendOnTextChanged(TextView.java:7988)
at android.widget.TextView.handleTextChanged(TextView.java:8050)
at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:10154)
at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:1033)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:559)
at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:225)
at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:224)
at android.view.inputmethod.BaseInputConnection.deleteSurroundingText(BaseInputConnection.java:244)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:389)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Network operations doesn't run

I have implemented Firebase Job Dispatcher in my project and I do some network operations when my job starts. Now It seems that these works that are being handled in different thread than main thread are not working correctly. Should I do something special to make them work?

The strange part is that when I debug my project and put a breakpoint on sending requests, the response arrives and there is no problem, But when I remove the breakpoints from the line that I'm sending request, debugger never halts on the response lines. I use Ion project for my network jobs.

What can I do to ensure that these network operations work safely?

Thanks,
Navid

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.