# RongJobIntentService

public abstract class RongJobIntentService

Helper for processing work that has been enqueued for a job/service. When running on Android O or later, the work will be dispatched as a job via JobScheduler.enqueue. When running on older versions of the platform, it will use Context.startService.

You must publish your subclass in your manifest for the system to interact with. This should be published as a android.app.job.JobService, as described for that class, since on O and later platforms it will be executed that way.

Use enqueueWork to enqueue new work to be dispatched to and handled by your service. It will be executed in onHandleWork.

You do not need to use androidx.legacy.content.WakefulBroadcastReceiver when using this class. When running on Android O, the JobScheduler will take care of wake locks for you (holding a wake lock from the time you enqueue work until the job has been dispatched and while it is running). When running on previous versions of the platform, this wake lock handling is emulated in the class here by directly calling the PowerManager; this means the application must request the WAKE_LOCK permission.

There are a few important differences in behavior when running on Android O or later as a Job vs. pre-O:

- When running as a pre-O service, the act of enqueueing work will generally start the service immediately, regardless of whether the device is dozing or in other conditions. When running as a Job, it will be subject to standard JobScheduler policies for a Job with a setOverrideDeadline of 0: the job will not run while the device is dozing, it may get delayed more than a service if the device is under strong memory pressure with lots of demand to run jobs.

- When running as a pre-O service, the normal service execution semantics apply: the service can run indefinitely, though the longer it runs the more likely the system will be to outright kill its process, and under memory pressure one should expect the process to be killed even of recently started services. When running as a Job, the typical execution time limit will apply, after which the job will be stopped (cleanly, not by killing the process) and rescheduled to continue its execution later. Job are generally not killed when the system is under memory pressure, since the number of concurrent jobs is adjusted based on the memory state of the device.

Here is an example implementation of this class:

#### See also

"frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/app/SimpleJobIntentService.java"

## Constructors

RongJobIntentService
Link copied to clipboard
public void RongJobIntentService()
Default empty constructor.

## Functions

enqueueWork
Link copied to clipboard
public static void enqueueWork(Context context, ComponentName component, int jobId, Intent work)
Like enqueueWork, but supplies a ComponentName for the service to interact with instead of its class.
public static void enqueueWork(Context context, Class cls, int jobId, Intent work)
Call this to enqueue work for your subclass of RongJobIntentService.
isStopped
Link copied to clipboard
public boolean isStopped()
Returns true if onStopCurrentWork has been called.
onBind
Link copied to clipboard
public IBinder onBind(Intent intent)
Returns the IBinder for the android.app.job.
onCreate
Link copied to clipboard
public void onCreate()
onDestroy
Link copied to clipboard
public void onDestroy()
onStartCommand
Link copied to clipboard
public int onStartCommand(Intent intent, int flags, int startId)
Processes start commands when running as a pre-O service, enqueueing them to be later dispatched in onHandleWork.
onStopCurrentWork
Link copied to clipboard
public boolean onStopCurrentWork()
This will be called if the JobScheduler has decided to stop this job.
setInterruptIfStopped
Link copied to clipboard
public void setInterruptIfStopped(boolean interruptIfStopped)
Control whether code executing in onHandleWork will be interrupted if the job is stopped.