JobIntentService

Added in 1.1.0
Deprecated in 1.6.0

abstract class JobIntentService : Service


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 android.app.job.JobService 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:

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.SystemClock;
import android.util.Log;
import android.widget.Toast;

import androidx.core.app.JobIntentService;

import org.jspecify.annotations.NonNull;

/**
 * Example implementation of a JobIntentService.
 */
public class SimpleJobIntentService extends JobIntentService {
    /**
     * Unique job ID for this service.
     */
    static final int JOB_ID = 1000;

    /**
     * Convenience method for enqueuing work in to this service.
     */
    static void enqueueWork(Context context, Intent work) {
        enqueueWork(context, SimpleJobIntentService.class, JOB_ID, work);
    }

    @Override
    protected void onHandleWork(@NonNull Intent intent) {
        // We have received work to do.  The system or framework is already
        // holding a wake lock for us at this point, so we can just go.
        Log.i("SimpleJobIntentService", "Executing work: " + intent);
        String label = intent.getStringExtra("label");
        if (label == null) {
            label = intent.toString();
        }
        toast("Executing: " + label);
        for (int i = 0; i < 5; i++) {
            Log.i("SimpleJobIntentService", "Running service " + (i + 1)
                    + "/5 @ " + SystemClock.elapsedRealtime());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
        }
        Log.i("SimpleJobIntentService", "Completed service @ " + SystemClock.elapsedRealtime());
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        toast("All work complete");
    }

    @SuppressWarnings("deprecation")
    final Handler mHandler = new Handler();

    // Helper for showing tests
    void toast(final CharSequence text) {
        mHandler.post(new Runnable() {
            @Override public void run() {
                Toast.makeText(SimpleJobIntentService.this, text, Toast.LENGTH_SHORT).show();
            }
        });
    }
}

Summary

Public constructors

This function is deprecated. Deprecated in Java

Public functions

java-static Unit
enqueueWork(context: Context, cls: Class<*>, jobId: Int, work: Intent)

This function is deprecated. Deprecated in Java

java-static Unit
enqueueWork(
    context: Context,
    component: ComponentName,
    jobId: Int,
    work: Intent
)

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

IBinder!
onBind(intent: Intent)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Int
onStartCommand(intent: Intent?, flags: Int, startId: Int)

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Unit
setInterruptIfStopped(interruptIfStopped: Boolean)

This function is deprecated. Deprecated in Java

Protected functions

abstract Unit

This function is deprecated. Deprecated in Java

Inherited Constants

From android.content.ComponentCallbacks2
const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated. Deprecated in Java

From android.content.Context
const String!
ACCESSIBILITY_SERVICE = "accessibility"

This property is deprecated. Deprecated in Java

const String!
ACCOUNT_SERVICE = "account"

This property is deprecated. Deprecated in Java

const String!
ACTIVITY_SERVICE = "activity"

This property is deprecated. Deprecated in Java

const String!
ADVANCED_PROTECTION_SERVICE = "advanced_protection"

This property is deprecated. Deprecated in Java

const String!
ALARM_SERVICE = "alarm"

This property is deprecated. Deprecated in Java

const String!
APPWIDGET_SERVICE = "appwidget"

This property is deprecated. Deprecated in Java

const String!
APP_FUNCTION_SERVICE = "app_function"

This property is deprecated. Deprecated in Java

const String!
APP_OPS_SERVICE = "appops"

This property is deprecated. Deprecated in Java

const String!
APP_SEARCH_SERVICE = "app_search"

This property is deprecated. Deprecated in Java

const String!
AUDIO_SERVICE = "audio"

This property is deprecated. Deprecated in Java

const String!
AUTOFILL_SERVICE = "autofill"

This property is deprecated. Deprecated in Java

const String!
BATTERY_SERVICE = "batterymanager"

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int
BIND_EXTERNAL_SERVICE = -2147483648

This property is deprecated. Deprecated in Java

const Long
BIND_EXTERNAL_SERVICE_LONG = 4611686018427387904

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const String!
BIOMETRIC_SERVICE = "biometric"

This property is deprecated. Deprecated in Java

const String!
BLOB_STORE_SERVICE = "blob_store"

This property is deprecated. Deprecated in Java

const String!
BLUETOOTH_SERVICE = "bluetooth"

This property is deprecated. Deprecated in Java

const String!
BUGREPORT_SERVICE = "bugreport"

This property is deprecated. Deprecated in Java

const String!
CAMERA_SERVICE = "camera"

This property is deprecated. Deprecated in Java

const String!
CAPTIONING_SERVICE = "captioning"

This property is deprecated. Deprecated in Java

const String!
CARRIER_CONFIG_SERVICE = "carrier_config"

This property is deprecated. Deprecated in Java

const String!
CHOOSER_SERVICE = "chooser"

This property is deprecated. Deprecated in Java

const String!
CLIPBOARD_SERVICE = "clipboard"

This property is deprecated. Deprecated in Java

const String!
COMPANION_DEVICE_SERVICE = "companiondevice"

This property is deprecated. Deprecated in Java

const String!
CONNECTIVITY_DIAGNOSTICS_SERVICE = "connectivity_diagnostics"

This property is deprecated. Deprecated in Java

const String!
CONNECTIVITY_SERVICE = "connectivity"

This property is deprecated. Deprecated in Java

const String!
CONSUMER_IR_SERVICE = "consumer_ir"

This property is deprecated. Deprecated in Java

const String!
CONTACT_KEYS_SERVICE = "contact_keys"

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const String!
CREDENTIAL_SERVICE = "credential"

This property is deprecated. Deprecated in Java

const String!
CROSS_PROFILE_APPS_SERVICE = "crossprofileapps"

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const String!
DEVICE_LOCK_SERVICE = "device_lock"

This property is deprecated. Deprecated in Java

const String!
DEVICE_POLICY_SERVICE = "device_policy"

This property is deprecated. Deprecated in Java

const String!
DISPLAY_HASH_SERVICE = "display_hash"

This property is deprecated. Deprecated in Java

const String!
DISPLAY_SERVICE = "display"

This property is deprecated. Deprecated in Java

const String!
DOMAIN_VERIFICATION_SERVICE = "domain_verification"

This property is deprecated. Deprecated in Java

const String!
DOWNLOAD_SERVICE = "download"

This property is deprecated. Deprecated in Java

const String!
DROPBOX_SERVICE = "dropbox"

This property is deprecated. Deprecated in Java

const String!
EUICC_SERVICE = "euicc"

This property is deprecated. Deprecated in Java

const String!
FILE_INTEGRITY_SERVICE = "file_integrity"

This property is deprecated. Deprecated in Java

const String!
FILE_SERVICE = "file"

This property is deprecated. Deprecated in Java

const String!
GAME_SERVICE = "game"

This property is deprecated. Deprecated in Java

const String!
GRAMMATICAL_INFLECTION_SERVICE = "grammatical_inflection"

This property is deprecated. Deprecated in Java

const String!
HARDWARE_PROPERTIES_SERVICE = "hardware_properties"

This property is deprecated. Deprecated in Java

const String!
HEALTHCONNECT_SERVICE = "healthconnect"

This property is deprecated. Deprecated in Java

const String!
INPUT_METHOD_SERVICE = "input_method"

This property is deprecated. Deprecated in Java

const String!
INPUT_SERVICE = "input"

This property is deprecated. Deprecated in Java

const String!
IPSEC_SERVICE = "ipsec"

This property is deprecated. Deprecated in Java

const String!
JOB_SCHEDULER_SERVICE = "jobscheduler"

This property is deprecated. Deprecated in Java

const String!
KEYGUARD_SERVICE = "keyguard"

This property is deprecated. Deprecated in Java

const String!
KEYSTORE_SERVICE = "keystore"

This property is deprecated. Deprecated in Java

const String!
LAUNCHER_APPS_SERVICE = "launcherapps"

This property is deprecated. Deprecated in Java

const String!
LAYOUT_INFLATER_SERVICE = "layout_inflater"

This property is deprecated. Deprecated in Java

const String!
LOCALE_SERVICE = "locale"

This property is deprecated. Deprecated in Java

const String!
LOCATION_SERVICE = "location"

This property is deprecated. Deprecated in Java

const String!
MEDIA_COMMUNICATION_SERVICE = "media_communication"

This property is deprecated. Deprecated in Java

const String!
MEDIA_METRICS_SERVICE = "media_metrics"

This property is deprecated. Deprecated in Java

const String!
MEDIA_PROJECTION_SERVICE = "media_projection"

This property is deprecated. Deprecated in Java

const String!
MEDIA_QUALITY_SERVICE = "media_quality"

This property is deprecated. Deprecated in Java

const String!
MEDIA_ROUTER_SERVICE = "media_router"

This property is deprecated. Deprecated in Java

const String!
MEDIA_SESSION_SERVICE = "media_session"

This property is deprecated. Deprecated in Java

const String!
MIDI_SERVICE = "midi"

This property is deprecated. Deprecated in Java

const Int
MODE_APPEND = 32768

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated.

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated.

const Int

This property is deprecated.

const String!

This property is deprecated. Deprecated in Java

const String!
NFC_SERVICE = "nfc"

This property is deprecated. Deprecated in Java

const String!
NOTIFICATION_SERVICE = "notification"

This property is deprecated. Deprecated in Java

const String!
NPU_SERVICE = "npu"

This property is deprecated. Deprecated in Java

const String!
NSD_SERVICE = "servicediscovery"

This property is deprecated. Deprecated in Java

const String!
OVERLAY_SERVICE = "overlay"

This property is deprecated. Deprecated in Java

const String!
PCC_SANDBOX_SERVICE = "pcc_sandbox"

This property is deprecated. Deprecated in Java

const String!
PEOPLE_SERVICE = "people"

This property is deprecated. Deprecated in Java

const String!
PERFORMANCE_HINT_SERVICE = "performance_hint"

This property is deprecated. Deprecated in Java

const String!
PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block"

This property is deprecated. Deprecated in Java

const String!
POWER_SERVICE = "power"

This property is deprecated. Deprecated in Java

const String!
PRINT_SERVICE = "print"

This property is deprecated. Deprecated in Java

const String!
PROFILING_SERVICE = "profiling"

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const String!
RESTRICTIONS_SERVICE = "restrictions"

This property is deprecated. Deprecated in Java

const String!
ROLE_SERVICE = "role"

This property is deprecated. Deprecated in Java

const String!
SATELLITE_SERVICE = "satellite"

This property is deprecated. Deprecated in Java

const String!
SEARCH_SERVICE = "search"

This property is deprecated. Deprecated in Java

const String!
SECURITY_STATE_SERVICE = "security_state"

This property is deprecated. Deprecated in Java

const String!
SENSOR_SERVICE = "sensor"

This property is deprecated. Deprecated in Java

const String!
SERIAL_SERVICE = "serial"

This property is deprecated. Deprecated in Java

const String!
SHORTCUT_SERVICE = "shortcut"

This property is deprecated. Deprecated in Java

const String!
STATUS_BAR_SERVICE = "statusbar"

This property is deprecated. Deprecated in Java

const String!
STORAGE_SERVICE = "storage"

This property is deprecated. Deprecated in Java

const String!
STORAGE_STATS_SERVICE = "storagestats"

This property is deprecated. Deprecated in Java

const String!
SYSTEM_HEALTH_SERVICE = "systemhealth"

This property is deprecated. Deprecated in Java

const String!
TELECOM_SERVICE = "telecom"

This property is deprecated. Deprecated in Java

const String!
TELEPHONY_IMS_SERVICE = "telephony_ims"

This property is deprecated. Deprecated in Java

const String!
TELEPHONY_PHONE_NUMBER_SERVICE = "telephony_phone_number"

This property is deprecated. Deprecated in Java

const String!

This property is deprecated. Deprecated in Java

const String!
TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service"

This property is deprecated. Deprecated in Java

const String!
TETHERING_SERVICE = "tethering"

This property is deprecated. Deprecated in Java

const String!
TEXT_CLASSIFICATION_SERVICE = "textclassification"

This property is deprecated. Deprecated in Java

const String!

This property is deprecated. Deprecated in Java

const String!
TV_AD_SERVICE = "tv_ad"

This property is deprecated. Deprecated in Java

const String!
TV_INPUT_SERVICE = "tv_input"

This property is deprecated. Deprecated in Java

const String!
TV_INTERACTIVE_APP_SERVICE = "tv_interactive_app"

This property is deprecated. Deprecated in Java

const String!
UI_MODE_SERVICE = "uimode"

This property is deprecated. Deprecated in Java

const String!
USAGE_STATS_SERVICE = "usagestats"

This property is deprecated. Deprecated in Java

const String!
USB_SERVICE = "usb"

This property is deprecated. Deprecated in Java

const String!
USER_SERVICE = "user"

This property is deprecated. Deprecated in Java

const String!
VIBRATOR_MANAGER_SERVICE = "vibrator_manager"

This property is deprecated. Deprecated in Java

const String!
VIBRATOR_SERVICE = "vibrator"

This property is deprecated.

const String!
VIRTUAL_DEVICE_SERVICE = "virtualdevice"

This property is deprecated. Deprecated in Java

const String!
VPN_MANAGEMENT_SERVICE = "vpn_management"

This property is deprecated. Deprecated in Java

const String!
WALLPAPER_SERVICE = "wallpaper"

This property is deprecated. Deprecated in Java

const String!
WEB_APP_SERVICE = "web_app"

This property is deprecated. Deprecated in Java

const String!
WIFI_AWARE_SERVICE = "wifiaware"

This property is deprecated. Deprecated in Java

const String!
WIFI_P2P_SERVICE = "wifip2p"

This property is deprecated. Deprecated in Java

const String!

This property is deprecated. Deprecated in Java

const String!
WIFI_SERVICE = "wifi"

This property is deprecated. Deprecated in Java

const String!
WINDOW_SERVICE = "window"

This property is deprecated. Deprecated in Java

From android.app.Service
const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated. Deprecated in Java

const Int

This property is deprecated.

const Int

This property is deprecated. Deprecated in Java

Inherited functions

From android.content.Context
Int

This function is deprecated. Deprecated in Java

ColorStateList!

This function is deprecated. Deprecated in Java

Drawable!

This function is deprecated. Deprecated in Java

String!
getString(resId: Int)

This function is deprecated. Deprecated in Java

T!
<T> getSystemService(serviceClass: Class<T!>!)

This function is deprecated. Deprecated in Java

CharSequence!
getText(resId: Int)

This function is deprecated. Deprecated in Java

Context.BindServiceFlags!

This function is deprecated. Deprecated in Java

TypedArray!

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit
sendBroadcastWithMultiplePermissions(
    intent: Intent!,
    receiverPermissions: Array<String!>!
)

This function is deprecated. Deprecated in Java

From android.content.ContextWrapper
Boolean
bindIsolatedService(
    service: Intent!,
    flags: Int,
    instanceName: String!,
    executor: Executor!,
    conn: ServiceConnection!
)

This function is deprecated. Deprecated in Java

Boolean
bindService(
    service: Intent!,
    flags: Context.BindServiceFlags!,
    executor: Executor!,
    conn: ServiceConnection!
)

This function is deprecated. Deprecated in Java

Boolean
bindServiceAsUser(
    service: Intent!,
    conn: ServiceConnection!,
    flags: Context.BindServiceFlags!,
    user: UserHandle!
)

This function is deprecated. Deprecated in Java

Int

This function is deprecated. Deprecated in Java

Int

This function is deprecated. Deprecated in Java

Array<Int>!
checkCallingOrSelfUriPermissions(
    uris: (Mutable)List<Uri!>!,
    modeFlags: Int
)

This function is deprecated. Deprecated in Java

Int

This function is deprecated. Deprecated in Java

Int
checkCallingUriPermission(uri: Uri!, modeFlags: Int)

This function is deprecated. Deprecated in Java

Array<Int>!
checkCallingUriPermissions(uris: (Mutable)List<Uri!>!, modeFlags: Int)

This function is deprecated. Deprecated in Java

Int
checkContentUriPermissionFull(uri: Uri!, pid: Int, uid: Int, modeFlags: Int)

This function is deprecated. Deprecated in Java

Int
checkPermission(permission: String!, pid: Int, uid: Int)

This function is deprecated. Deprecated in Java

Int

This function is deprecated. Deprecated in Java

Int
checkUriPermission(uri: Uri!, pid: Int, uid: Int, modeFlags: Int)

This function is deprecated. Deprecated in Java

Array<Int>!
checkUriPermissions(
    uris: (Mutable)List<Uri!>!,
    pid: Int,
    uid: Int,
    modeFlags: Int
)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated.

Context!
createAttributionContext(attributionTag: String!)

This function is deprecated. Deprecated in Java

Context!
createConfigurationContext(overrideConfiguration: Configuration!)

This function is deprecated. Deprecated in Java

Context!
createContext(contextParams: ContextParams!)

This function is deprecated. Deprecated in Java

Context!

This function is deprecated. Deprecated in Java

Context!

This function is deprecated. Deprecated in Java

Context!

This function is deprecated. Deprecated in Java

Context!

This function is deprecated. Deprecated in Java

Context!
createPackageContext(packageName: String!, flags: Int)

This function is deprecated. Deprecated in Java

Context!
createWindowContext(display: Display!, type: Int, options: Bundle!)

This function is deprecated. Deprecated in Java

Array<String!>!

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Unit
enforceCallingOrSelfPermission(permission: String!, message: String!)

This function is deprecated. Deprecated in Java

Unit
enforceCallingOrSelfUriPermission(
    uri: Uri!,
    modeFlags: Int,
    message: String!
)

This function is deprecated. Deprecated in Java

Unit
enforceCallingPermission(permission: String!, message: String!)

This function is deprecated. Deprecated in Java

Unit
enforceCallingUriPermission(uri: Uri!, modeFlags: Int, message: String!)

This function is deprecated. Deprecated in Java

Unit
enforcePermission(permission: String!, pid: Int, uid: Int, message: String!)

This function is deprecated. Deprecated in Java

Unit
enforceUriPermission(
    uri: Uri!,
    pid: Int,
    uid: Int,
    modeFlags: Int,
    message: String!
)

This function is deprecated. Deprecated in Java

Array<String!>!

This function is deprecated. Deprecated in Java

Context!

This function is deprecated. Deprecated in Java

ApplicationInfo!

This function is deprecated. Deprecated in Java

AssetManager!

This function is deprecated. Deprecated in Java

AttributionSource!

This function is deprecated. Deprecated in Java

String!

This function is deprecated. Deprecated in Java

Context!

This function is deprecated. Deprecated in Java

File!

This function is deprecated. Deprecated in Java

ClassLoader!

This function is deprecated. Deprecated in Java

File!

This function is deprecated. Deprecated in Java

ContentResolver!

This function is deprecated. Deprecated in Java

File!

This function is deprecated. Deprecated in Java

File!

This function is deprecated. Deprecated in Java

Int

This function is deprecated. Deprecated in Java

File!
getDir(name: String!, mode: Int)

This function is deprecated. Deprecated in Java

Display!

This function is deprecated. Deprecated in Java

File!

This function is deprecated. Deprecated in Java

Array<File!>!

This function is deprecated. Deprecated in Java

File!

This function is deprecated. Deprecated in Java

Array<File!>!

This function is deprecated. Deprecated in Java

Array<File!>!

This function is deprecated.

File!

This function is deprecated. Deprecated in Java

File!

This function is deprecated. Deprecated in Java

Executor!

This function is deprecated. Deprecated in Java

Looper!

This function is deprecated. Deprecated in Java

File!

This function is deprecated. Deprecated in Java

File!

This function is deprecated. Deprecated in Java

Array<File!>!

This function is deprecated. Deprecated in Java

String!

This function is deprecated. Deprecated in Java

String!

This function is deprecated. Deprecated in Java

PackageManager!

This function is deprecated. Deprecated in Java

String!

This function is deprecated. Deprecated in Java

String!

This function is deprecated. Deprecated in Java

ContextParams!

This function is deprecated. Deprecated in Java

Resources!

This function is deprecated. Deprecated in Java

SharedPreferences!
getSharedPreferences(name: String!, mode: Int)

This function is deprecated. Deprecated in Java

Any!

This function is deprecated. Deprecated in Java

String!
getSystemServiceName(serviceClass: Class<*>!)

This function is deprecated. Deprecated in Java

Resources.Theme!

This function is deprecated. Deprecated in Java

Drawable!

This function is deprecated.

Int

This function is deprecated.

Int

This function is deprecated.

Unit
grantUriPermission(toPackage: String!, uri: Uri!, modeFlags: Int)

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Boolean
moveDatabaseFrom(sourceContext: Context!, name: String!)

This function is deprecated. Deprecated in Java

Boolean
moveSharedPreferencesFrom(sourceContext: Context!, name: String!)

This function is deprecated. Deprecated in Java

FileInputStream!

This function is deprecated. Deprecated in Java

FileOutputStream!
openFileOutput(name: String!, mode: Int)

This function is deprecated. Deprecated in Java

SQLiteDatabase!
openOrCreateDatabase(
    name: String!,
    mode: Int,
    factory: SQLiteDatabase.CursorFactory!
)

This function is deprecated. Deprecated in Java

Drawable!

This function is deprecated.

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Intent!

This function is deprecated. Deprecated in Java

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated. Deprecated in Java

Unit
revokeUriPermission(uri: Uri!, modeFlags: Int)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit
sendOrderedBroadcast(
    intent: Intent!,
    initialCode: Int,
    receiverPermission: String!,
    receiverAppOp: String!,
    resultReceiver: BroadcastReceiver!,
    scheduler: Handler!,
    initialData: String!,
    initialExtras: Bundle!,
    options: Bundle!
)

This function is deprecated. Deprecated in Java

Unit
sendOrderedBroadcastAsUser(
    intent: Intent!,
    user: UserHandle!,
    receiverPermission: String!,
    resultReceiver: BroadcastReceiver!,
    scheduler: Handler!,
    initialCode: Int,
    initialData: String!,
    initialExtras: Bundle!
)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
sendStickyOrderedBroadcast(
    intent: Intent!,
    resultReceiver: BroadcastReceiver!,
    scheduler: Handler!,
    initialCode: Int,
    initialData: String!,
    initialExtras: Bundle!
)

This function is deprecated.

Unit
sendStickyOrderedBroadcastAsUser(
    intent: Intent!,
    user: UserHandle!,
    resultReceiver: BroadcastReceiver!,
    scheduler: Handler!,
    initialCode: Int,
    initialData: String!,
    initialExtras: Bundle!
)

This function is deprecated.

Unit
setTheme(resid: Int)

This function is deprecated. Deprecated in Java

Unit
setWallpaper(bitmap: Bitmap!)

This function is deprecated.

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

ComponentName!

This function is deprecated. Deprecated in Java

Boolean
startInstrumentation(
    className: ComponentName!,
    profileFile: String!,
    arguments: Bundle!
)

This function is deprecated. Deprecated in Java

Unit
startIntentSender(
    intent: IntentSender!,
    fillInIntent: Intent!,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int
)

This function is deprecated. Deprecated in Java

ComponentName!
startService(service: Intent!)

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit
updateServiceGroup(conn: ServiceConnection!, group: Int, importance: Int)

This function is deprecated. Deprecated in Java

From android.app.Service
Unit

This function is deprecated. Deprecated in Java

Unit
dump(fd: FileDescriptor!, writer: PrintWriter!, args: Array<String!>!)

This function is deprecated. Deprecated in Java

Application!

This function is deprecated. Deprecated in Java

Int

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated.

Unit
onRebind(intent: Intent!)

This function is deprecated. Deprecated in Java

Unit
onStart(intent: Intent!, startId: Int)

This function is deprecated.

Unit
onTaskRemoved(rootIntent: Intent!)

This function is deprecated. Deprecated in Java

Unit
onTimeout(startId: Int)

This function is deprecated. Deprecated in Java

Unit
onTrimMemory(level: Int)

This function is deprecated. Deprecated in Java

Boolean
onUnbind(intent: Intent!)

This function is deprecated. Deprecated in Java

Unit
startForeground(id: Int, notification: Notification!)

This function is deprecated. Deprecated in Java

Unit
stopForeground(removeNotification: Boolean)

This function is deprecated.

Unit

This function is deprecated. Deprecated in Java

Boolean
stopSelfResult(startId: Int)

This function is deprecated. Deprecated in Java

Public constructors

JobIntentService

Added in 1.1.0
Deprecated in 1.6.0
JobIntentService()

Default empty constructor.

Public functions

enqueueWork

Added in 1.2.0
Deprecated in 1.6.0
java-static fun enqueueWork(context: Context, cls: Class<*>, jobId: Int, work: Intent): Unit

Call this to enqueue work for your subclass of JobIntentService. This will either directly start the service (when running on pre-O platforms) or enqueue work for it as a job (when running on O and later). In either case, a wake lock will be held for you to ensure you continue running. The work you enqueue will ultimately appear at onHandleWork.

Parameters
context: Context

Context this is being called from.

cls: Class<*>

The concrete class the work should be dispatched to (this is the class that is published in your manifest).

jobId: Int

A unique job ID for scheduling; must be the same value for all work enqueued for the same class.

work: Intent

The Intent of work to enqueue.

enqueueWork

Added in 1.1.0
Deprecated in 1.6.0
java-static fun enqueueWork(
    context: Context,
    component: ComponentName,
    jobId: Int,
    work: Intent
): Unit

Like enqueueWork, but supplies a ComponentName for the service to interact with instead of its class.

Parameters
context: Context

Context this is being called from.

component: ComponentName

The published ComponentName of the class this work should be dispatched to.

jobId: Int

A unique job ID for scheduling; must be the same value for all work enqueued for the same class.

work: Intent

The Intent of work to enqueue.

isStopped

Added in 1.1.0
Deprecated in 1.6.0
fun isStopped(): Boolean

Returns true if onStopCurrentWork has been called. You can use this, while executing your work, to see if it should be stopped.

onBind

Added in 1.1.0
Deprecated in 1.6.0
fun onBind(intent: Intent): IBinder!

Returns the IBinder for the android.app.job.JobServiceEngine when running as a JobService on O and later platforms.

onCreate

fun onCreate(): Unit

onDestroy

fun onDestroy(): Unit

onStartCommand

fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int

Processes start commands when running as a pre-O service, enqueueing them to be later dispatched in onHandleWork.

onStopCurrentWork

Added in 1.1.0
Deprecated in 1.6.0
fun onStopCurrentWork(): Boolean

This will be called if the JobScheduler has decided to stop this job. The job for this service does not have any constraints specified, so this will only generally happen if the service exceeds the job's maximum execution time.

Returns
Boolean

True to indicate to the JobManager whether you'd like to reschedule this work, false to drop this and all following work. Regardless of the value returned, your service must stop executing or the system will ultimately kill it. The default implementation returns true, and that is most likely what you want to return as well (so no work gets lost).

setInterruptIfStopped

Added in 1.1.0
Deprecated in 1.6.0
fun setInterruptIfStopped(interruptIfStopped: Boolean): Unit

Control whether code executing in onHandleWork will be interrupted if the job is stopped. By default this is false. If called and set to true, any time onStopCurrentWork is called, the class will first call AsyncTask.cancel(true) to interrupt the running task.

Parameters
interruptIfStopped: Boolean

Set to true to allow the system to interrupt actively running work.

Protected functions

onHandleWork

Added in 1.1.0
Deprecated in 1.6.0
protected abstract fun onHandleWork(intent: Intent): Unit

Called serially for each work dispatched to and processed by the service. This method is called on a background thread, so you can do long blocking operations here. Upon returning, that work will be considered complete and either the next pending work dispatched here or the overall service destroyed now that it has nothing else to do.

Be aware that when running as a job, you are limited by the maximum job execution time and any single or total sequential items of work that exceeds that limit will cause the service to be stopped while in progress and later restarted with the last unfinished work. (There is currently no limit on execution duration when running as a pre-O plain Service.)

Parameters
intent: Intent

The intent describing the work to now be processed.