public abstract class GCMBaseIntentService
extends android.app.IntentService
IntentService
s responsible for
handling communication from Google Cloud Messaging service.
The abstract methods in this class are called from its worker thread, and hence should run in a limited amount of time. If they execute long operations, they should spawn new threads, otherwise the worker thread will be blocked.
Subclasses must provide a public no-arg constructor.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
TAG |
START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, AUDIO_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_WAIVE_PRIORITY, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, DEVICE_POLICY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, KEYGUARD_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_ROUTER_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, POWER_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, STORAGE_SERVICE, TELEPHONY_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, UI_MODE_SERVICE, USB_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
Modifier | Constructor and Description |
---|---|
protected |
GCMBaseIntentService()
Constructor that does not set a sender id, useful when the sender id
is context-specific.
|
protected |
GCMBaseIntentService(java.lang.String... senderIds)
Constructor used when the sender id(s) is fixed.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.String[] |
getSenderIds(android.content.Context context)
Gets the sender ids.
|
protected void |
onDeletedMessages(android.content.Context context,
int total)
Called when the GCM server tells pending messages have been deleted
because the device was idle.
|
protected abstract void |
onError(android.content.Context context,
java.lang.String errorId)
Called on registration or unregistration error.
|
void |
onHandleIntent(android.content.Intent intent) |
protected abstract void |
onMessage(android.content.Context context,
android.content.Intent intent)
Called when a cloud message has been received.
|
protected boolean |
onRecoverableError(android.content.Context context,
java.lang.String errorId)
Called on a registration error that could be retried.
|
protected abstract void |
onRegistered(android.content.Context context,
java.lang.String registrationId)
Called after a device has been registered.
|
protected abstract void |
onUnregistered(android.content.Context context,
java.lang.String registrationId)
Called after a device has been unregistered.
|
onBind, onCreate, onDestroy, onStart, onStartCommand, setIntentRedelivery
dump, getApplication, onConfigurationChanged, onLowMemory, onRebind, onTaskRemoved, onTrimMemory, onUnbind, startForeground, stopForeground, stopSelf, stopSelf, stopSelfResult
attachBaseContext, bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createPackageContext, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getCacheDir, getClassLoader, getContentResolver, getDatabasePath, getDir, getExternalCacheDir, getExternalFilesDir, getFilesDir, getFileStreamPath, getMainLooper, getObbDir, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSystemService, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isRestricted, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, removeStickyBroadcast, revokeUriPermission, sendBroadcast, sendBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendStickyBroadcast, sendStickyOrderedBroadcast, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivity, startActivity, startInstrumentation, startIntentSender, startIntentSender, startService, stopService, unbindService, unregisterReceiver
public static final java.lang.String TAG
protected GCMBaseIntentService()
When using this constructor, the subclass must
override getSenderIds(Context)
, otherwise methods such as
onHandleIntent(Intent)
will throw an
IllegalStateException
on runtime.
protected GCMBaseIntentService(java.lang.String... senderIds)
protected java.lang.String[] getSenderIds(android.content.Context context)
By default, it returns the sender ids passed in the constructor, but it could be overridden to provide a dynamic sender id.
java.lang.IllegalStateException
- if sender id was not set on constructor.protected abstract void onMessage(android.content.Context context, android.content.Intent intent)
context
- application's context.intent
- intent containing the message payload as extras.protected void onDeletedMessages(android.content.Context context, int total)
context
- application's context.total
- total number of collapsed messagesprotected boolean onRecoverableError(android.content.Context context, java.lang.String errorId)
By default, it does nothing and returns true, but could be overridden to change that behavior and/or display the error.
context
- application's context.errorId
- error id returned by the GCM service.protected abstract void onError(android.content.Context context, java.lang.String errorId)
context
- application's context.errorId
- error id returned by the GCM service.protected abstract void onRegistered(android.content.Context context, java.lang.String registrationId)
context
- application's context.registrationId
- the registration id returned by the GCM service.protected abstract void onUnregistered(android.content.Context context, java.lang.String registrationId)
registrationId
- the registration id that was previously registered.context
- application's context.public final void onHandleIntent(android.content.Intent intent)
onHandleIntent
in class android.app.IntentService