Package 

Class HeadlessJsTaskService

  • All Implemented Interfaces:
    android.content.ComponentCallbacks , android.content.ComponentCallbacks2 , com.facebook.react.jstasks.HeadlessJsTaskEventListener

    
    public abstract class HeadlessJsTaskService
    extends Service implements HeadlessJsTaskEventListener
                        

    Base class for running JS without a UI. Generally, you only need to override , which is called for every onStartCommand. The result, if not {@code * null}, is used to run a JS task.

    If you need more fine-grained control over how tasks are run, you can override and call startTask depending on your custom logic.

    If you're starting a {@code HeadlessJsTaskService} from a {@code BroadcastReceiver} (e.g. handling push notifications), make sure to call acquireWakeLockNow before returning from onReceive, to make sure the device doesn't go to sleep before the service is started.

    • Method Summary

      Modifier and Type Method Description
      int onStartCommand(Intent intent, int flags, int startId)
      static void acquireWakeLockNow(Context context) Acquire a wake lock to ensure the device doesn't go to sleep while processing background tasks.
      IBinder onBind(Intent intent)
      void onDestroy()
      void onHeadlessJsTaskStart(int taskId) Called when a JS task is started, on the UI thread.
      void onHeadlessJsTaskFinish(int taskId) Called when a JS task finishes (i.e.
      • Methods inherited from class android.app.Service

        getApplication, getForegroundServiceType, onBind, onConfigurationChanged, onCreate, onDestroy, onLowMemory, onRebind, onStart, onStartCommand, onTaskRemoved, onTrimMemory, onUnbind, startForeground, stopForeground, stopSelf, stopSelfResult
      • Methods inherited from class android.content.ContextWrapper

        bindIsolatedService, bindService, bindServiceAsUser, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingOrSelfUriPermissions, checkCallingPermission, checkCallingUriPermission, checkCallingUriPermissions, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermissions, clearWallpaper, createAttributionContext, createConfigurationContext, createContext, createContextForSplit, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, createWindowContext, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getAttributionSource, getAttributionTag, getBaseContext, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDataDir, getDatabasePath, getDir, getDisplay, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFileStreamPath, getFilesDir, getMainExecutor, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getOpPackageName, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getParams, getResources, getSharedPreferences, getSystemService, getSystemServiceName, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isDeviceProtectedStorage, isRestricted, isUiContext, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, peekWallpaper, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, sendBroadcast, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, startActivities, startActivity, startForegroundService, startInstrumentation, startIntentSender, startService, stopService, unbindService, unregisterReceiver, updateServiceGroup
      • Methods inherited from class android.content.Context

        getColor, getColorStateList, getDrawable, getString, getSystemService, getText, obtainStyledAttributes, registerComponentCallbacks, sendBroadcastWithMultiplePermissions, unregisterComponentCallbacks
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • acquireWakeLockNow

         static void acquireWakeLockNow(Context context)

        Acquire a wake lock to ensure the device doesn't go to sleep while processing background tasks.

      • onHeadlessJsTaskStart

         void onHeadlessJsTaskStart(int taskId)

        Called when a JS task is started, on the UI thread.

        Parameters:
        taskId - the unique identifier of this task instance
      • onHeadlessJsTaskFinish

         void onHeadlessJsTaskFinish(int taskId)

        Called when a JS task finishes (i.e. when is called, or when it times out), on the UIthread.