Wish Android Job Scheduler

Peter Simpson

Expert
Licensed User
Longtime User
The title says it all.

A nice and easy way to implement Android Job Scheduler, please see this link https://developer.android.com/about/versions/oreo/background.html#overview.

I have a strange feeling that you're going to say use a notifications to add a icon at the top of the screen to keep the service running ;)

Please note that I personally do not actually need this feature as none of my apps are effected. But I've come across a post and while testing in Android V8.1.0 I realised that there might be an issue in the future that does not effect me right now, phew. Maybe it's something that you already know a logical workaround for (without adding a notification icon to the notification area).

Anyway, it's just a though...
 

DonManfred

Expert
Licensed User
Longtime User

DonManfred

Expert
Licensed User
Longtime User
I didn't even realise that there was a library until @XbNnX_507 mentioned it...
me too. I started to do a wrap for the Android Job sheduler (this thread). But i failed
I give it another go on the posted lib....
 

DonManfred

Expert
Licensed User
Longtime User
I think it is mandatory to create own (specialized) JOBCreator-Classes to use this Library...

B4X:
public class DemoJobCreator implements JobCreator {

    @Override
    @Nullable
    public Job create(@NonNull String tag) {
        switch (tag) {
            case DemoSyncJob.TAG:
                return new DemoSyncJob();
            default:
                return null;
        }
    }
}

After that you can start scheduling jobs.

B4X:
public class DemoSyncJob extends Job {

    public static final String TAG = "job_demo_tag";

    @Override
    @NonNull
    protected Result onRunJob(Params params) {
        // run your job here
        return Result.SUCCESS;
    }

    public static void scheduleJob() {
        new JobRequest.Builder(DemoSyncJob.TAG)
                .setExecutionWindow(30_000L, 40_000L)
                .build()
                .schedule();
    }
}

in this case the creator will always create a specific Job which we, the developers, need to use in the java project....

I´m not sure if it will work with a simple wrapper for this. We´ll see...
Hopefully i can post a 1st version to test today
 

DonManfred

Expert
Licensed User
Longtime User
It is partially working as of now...

*** Service (starter) Create ***
** Service (starter) Start **
Jobrequest created... Scheduling job
null
[request{id=8, tag=ReScheduling, transient=false}, request{id=11, tag=ReScheduling, transient=false}, request{id=13, tag=ReScheduling, transient=false}, request{id=22, tag=ReScheduling, transient=false}, request{id=19, tag=ReScheduling, transient=false}, request{id=3, tag=ReScheduling, transient=false}, request{id=4, tag=ReScheduling, transient=false}, request{id=15, tag=ReScheduling, transient=false}, request{id=18, tag=ReScheduling, transient=false}, request{id=23, tag=ReScheduling, transient=false}, request{id=9, tag=ReScheduling, transient=false}, request{id=24, tag=ReScheduling, transient=false}, request{id=17, tag=ReScheduling, transient=false}, request{id=12, tag=ReScheduling, transient=false}, request{id=21, tag=ReScheduling, transient=false}, request{id=10, tag=ReScheduling, transient=false}, request{id=14, tag=ReScheduling, transient=false}, request{id=16, tag=ReScheduling, transient=false}, request{id=7, tag=ReScheduling, transient=false}, request{id=20, tag=ReScheduling, transient=false}, request{id=2, tag=ReScheduling, transient=false}]
{}
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
createJob(ReScheduling) <----- This LOG comes from the JobCreator class inside the lib.
created MyReschedulingJob(ReScheduling) ' This too

i also can see more info in the unfiltered log

Run job, request{id=15, tag=ReScheduling, transient=false}, waited 00:55:20, interval 00:15:00, flex 00:05:00
createJob(ReScheduling)
created MyReschedulingJob(ReScheduling)
Executing request{id=15, tag=ReScheduling, transient=false}, context PlatformJobService
Finished job{id=15, finished=true, result=null, canceled=false, periodic=true, class=MyReschedulingJob, tag=ReScheduling}
Run job, request{id=3, tag=ReScheduling, transient=false}, waited 02:10:03, interval 00:15:00, flex 00:05:00
createJob(ReScheduling)
created MyReschedulingJob(ReScheduling)
Executing request{id=3, tag=ReScheduling, transient=false}, context PlatformJobService
Finished job{id=3, finished=true, result=null, canceled=false, periodic=true, class=MyReschedulingJob, tag=ReScheduling}
Finished job, request{id=15, tag=ReScheduling, transient=false} null

But the event to run the job does not raise. I need to investigate more....
 

dcoun

Member
Licensed User
Longtime User
Not sure. It will take some time for this feature to be added and it will probably won't be a "job scheduler library" but rather a more flexible way to work with receivers and how they interact with services.
Hi, do we have a roadmap for that?
 
Top