CloudPlugs REST Library  1.0.0
for Android
BaseService Class Referenceabstract

Base service class to handle background execution with an automatic mechanism of Android CPU wake locks. This class is for internal usage. More...

Inheritance diagram for BaseService:

Public Member Functions

final int onStartCommand (Intent intent, int flags, int id)
 
abstract int startService (Intent intent, int startId)
 
IBinder onBind (Intent i)
 

Static Public Member Functions

static synchronized int getNumOfHeldWakeLocks ()
 

Static Public Attributes

static final String EXT_WAKE_ID = NAME + ".wakeLockId"
 
static final int ID_NULL = 0
 
static final int WAKE_LOCK_TIMEOUT = 60*1000
 

Static Protected Member Functions

static void addWakeLockId (Context ctx, Intent intent, Integer wakeLockId, boolean createIfNotExists)
 
static void addWakeLock (Context ctx, Intent i)
 
static Integer registerWakeLock (WakeLock wakeLock)
 
static WakeLock acquireWakeLock (Context ctx, String tag, long timeout)
 

Detailed Description

Base service class to handle background execution with an automatic mechanism of Android CPU wake locks. This class is for internal usage.

Member Function Documentation

◆ acquireWakeLock()

static WakeLock acquireWakeLock ( Context  ctx,
String  tag,
long  timeout 
)
staticprotected

Acquires a wake lock. ctx the android.content.Context

Parameters
tagthe tag to supply to android.os.PowerManager
timeoutthe wake lock timeout
Returns
a new android.os.PowerManager.WakeLock instance

◆ addWakeLock()

static void addWakeLock ( Context  ctx,
Intent  i 
)
staticprotected

Adds a new wake lock to the specified intent. This will add the wake lock to the central wake lock registry managed by this class.

Parameters
ctxthe android.content.Context
ithe Intent to add the wake lock ID as extra to (never null)

◆ addWakeLockId()

static void addWakeLockId ( Context  ctx,
Intent  intent,
Integer  wakeLockId,
boolean  createIfNotExists 
)
staticprotected

Adds an existing wake lock identified by its registry ID to the specified intent.

Parameters
intentthe android.content.Intent to add the wake lock ID as extra to (never null)
wakeLockIdthe wake lock registry ID of an existing wake lock or null
createIfNotExistsif wakeLockId is null and this parameter is truetrue a new wake lock is created, registered, and added to intent

◆ getNumOfHeldWakeLocks()

static synchronized int getNumOfHeldWakeLocks ( )
static

◆ onBind()

IBinder onBind ( Intent  i)

◆ onStartCommand()

final int onStartCommand ( Intent  intent,
int  flags,
int  id 
)

◆ registerWakeLock()

static Integer registerWakeLock ( WakeLock  wakeLock)
staticprotected

Registers a wake lock with the wake lock registry.

Parameters
wakeLockthe android.os.PowerManager.WakeLock instance that should be registered with the wake lock registry (never null)
Returns
the ID that identifies this wake lock in the registry

◆ startService()

abstract int startService ( Intent  intent,
int  startId 
)
abstract

Subclasses need to implement this instead of overriding onStartCommand(Intent, int, int). This allows android.app.Service to manage the service lifecycle, including wake lock management.

Parameters
intentthe Intent supplied to android.content.Context::startService(Intent)
startIda unique integer representing this specific request to start
Returns
the return value indicates what semantics the system should use for the service's current started state. It may be one of the constants associated with the android.app.Service::START_CONTINUATION_MASK bits.

Member Data Documentation

◆ EXT_WAKE_ID

final String EXT_WAKE_ID = NAME + ".wakeLockId"
static

◆ ID_NULL

final int ID_NULL = 0
static

◆ WAKE_LOCK_TIMEOUT

final int WAKE_LOCK_TIMEOUT = 60*1000
static