{
	"id": "bb44fbc6-e2d0-4107-91c2-ccbc7c8977bf",
	"created_at": "2026-04-06T02:11:19.74769Z",
	"updated_at": "2026-04-10T13:12:53.823003Z",
	"deleted_at": null,
	"sha1_hash": "790ee104c446c06ab96bd650653b242662aea0f6",
	"title": "Services overview",
	"llm_title": "",
	"authors": "",
	"file_creation_date": "0001-01-01T00:00:00Z",
	"file_modification_date": "0001-01-01T00:00:00Z",
	"file_size": 259264,
	"plain_text": "Services overview\r\nArchived: 2026-04-06 01:53:07 UTC\r\nA Service is an application component that can perform long-running operations in the background. It does not\r\nprovide a user interface. Once started, a service might continue running for some time, even after the user\r\nswitches to another application. Additionally, a component can bind to a service to interact with it and even\r\nperform interprocess communication (IPC). For example, a service can handle network transactions, play music,\r\nperform file I/O, or interact with a content provider, all from the background.\r\nCaution: A service runs in the main thread of its hosting process; the service does not create its own thread and\r\ndoes not run in a separate process unless you specify otherwise. You should run any blocking operations on a\r\nseparate thread within the service to avoid Application Not Responding (ANR) errors.\r\nTypes of Services\r\nThese are the three different types of services:\r\nForeground\r\nA foreground service performs some operation that is noticeable to the user. For example, an audio app\r\nwould use a foreground service to play an audio track. Foreground services must display a Notification.\r\nForeground services continue running even when the user isn't interacting with the app.\r\nWhen you use a foreground service, you must display a notification so that users are actively aware that the\r\nservice is running. This notification cannot be dismissed unless the service is either stopped or removed\r\nfrom the foreground.\r\nLearn more about how to configure foreground services in your app.\r\nNote: The WorkManager API offers a flexible way of scheduling tasks, and is able to run these jobs as\r\nforeground services if needed. In many cases, using WorkManager is preferable to using foreground\r\nservices directly.\r\nBackground\r\nA background service performs an operation that isn't directly noticed by the user. For example, if an app\r\nused a service to compact its storage, that would usually be a background service.\r\nNote: If your app targets API level 26 or higher, the system imposes restrictions on running background\r\nservices when the app itself isn't in the foreground. In most situations, for example, you shouldn't access\r\nlocation information from the background. Instead, schedule tasks using WorkManager.\r\nBound\r\nA service is bound when an application component binds to it by calling bindService() . A bound service\r\noffers a client-server interface that allows components to interact with the service, send requests, receive\r\nhttps://developer.android.com/guide/components/services.html#Foreground\r\nPage 1 of 14\n\nresults, and even do so across processes with interprocess communication (IPC). A bound service runs only\r\nas long as another application component is bound to it. Multiple components can bind to the service at\r\nonce, but when all of them unbind, the service is destroyed.\r\nAlthough this documentation generally discusses started and bound services separately, your service can work\r\nboth ways—it can be started (to run indefinitely) and also allow binding. It's simply a matter of whether you\r\nimplement a couple of callback methods: onStartCommand() to allow components to start it and onBind() to\r\nallow binding.\r\nRegardless of whether your service is started, bound, or both, any application component can use the service (even\r\nfrom a separate application) in the same way that any component can use an activity—by starting it with an\r\nIntent . However, you can declare the service as private in the manifest file and block access from other\r\napplications. This is discussed more in the section about Declaring the service in the manifest.\r\nChoosing between a service and a thread\r\nA service is simply a component that can run in the background, even when the user is not interacting with your\r\napplication, so you should create a service only if that is what you need.\r\nIf you must perform work outside of your main thread, but only while the user is interacting with your application,\r\nyou should instead create a new thread in the context of another application component. For example, if you want\r\nto play some music, but only while your activity is running, you might create a thread in onCreate() , start\r\nrunning it in onStart() , and stop it in onStop() . Also consider using thread pools and executors from the\r\njava.util.concurrent package or Kotlin coroutines instead of the traditional Thread class. See the Threading\r\non Android document for more information about moving execution to background threads.\r\nRemember that if you do use a service, it still runs in your application's main thread by default, so you should still\r\ncreate a new thread within the service if it performs intensive or blocking operations.\r\nThe basics\r\nTo create a service, you must create a subclass of Service or use one of its existing subclasses. In your\r\nimplementation, you must override some callback methods that handle key aspects of the service lifecycle and\r\nprovide a mechanism that allows the components to bind to the service, if appropriate. These are the most\r\nimportant callback methods that you should override:\r\nonStartCommand()\r\nThe system invokes this method by calling startService() when another component (such as an\r\nactivity) requests that the service be started. When this method executes, the service is started and can run\r\nin the background indefinitely. If you implement this, it is your responsibility to stop the service when its\r\nwork is complete by calling stopSelf() or stopService() . If you only want to provide binding, you\r\ndon't need to implement this method.\r\nonBind()\r\nThe system invokes this method by calling bindService() when another component wants to bind with\r\nthe service (such as to perform RPC). In your implementation of this method, you must provide an\r\nhttps://developer.android.com/guide/components/services.html#Foreground\r\nPage 2 of 14\n\ninterface that clients use to communicate with the service by returning an IBinder . You must always\nimplement this method; however, if you don't want to allow binding, you should return null.\nonCreate()\nThe system invokes this method to perform one-time setup procedures when the service is initially created\n(before it calls either onStartCommand() or onBind() ). If the service is already running, this method is\nnot called.\nonDestroy()\nThe system invokes this method when the service is no longer used and is being destroyed. Your service\nshould implement this to clean up any resources such as threads, registered listeners, or receivers. This is\nthe last call that the service receives.\nIf a component starts the service by calling startService() (which results in a call to onStartCommand() ), the\nservice continues to run until it stops itself with stopSelf() or another component stops it by calling\nstopService() .\nIf a component calls bindService() to create the service and onStartCommand() is not called, the service runs\nonly as long as the component is bound to it. After the service is unbound from all of its clients, the system\ndestroys it.\nThe Android system stops a service only when memory is low and it must recover system resources for the\nactivity that has user focus. If the service is bound to an activity that has user focus, it's less likely to be killed; if\nthe service is declared to run in the foreground, it's rarely killed. If the service is started and is long-running, the\nsystem lowers its position in the list of background tasks over time, and the service becomes highly susceptible to\nkilling—if your service is started, you must design it to gracefully handle restarts by the system. If the system kills\nyour service, it restarts it as soon as resources become available, but this also depends on the value that you return\nfrom onStartCommand() . For more information about when the system might destroy a service, see the Processes\nand Threading document.\nIn the following sections, you'll see how you can create the startService() and bindService() service\nmethods, as well as how to use them from other application components.\nDeclaring a service in the manifest\nYou must declare all services in your application's manifest file, just as you do for activities and other\ncomponents.\nTo declare your service, add a element as a child of the element. Here is an\nexample:\n... ...\nhttps://developer.android.com/guide/components/services.html#Foreground\nPage 3 of 14\n\n\u003c/application\u003e\r\n\u003c/manifest\u003e\r\nSee the \u003cservice\u003e element reference for more information about declaring your service in the manifest.\r\nThere are other attributes that you can include in the \u003cservice\u003e element to define properties such as the\r\npermissions that are required to start the service and the process in which the service should run. The\r\nandroid:name attribute is the only required attribute—it specifies the class name of the service. After you\r\npublish your application, leave this name unchanged to avoid the risk of breaking code due to dependence on\r\nexplicit intents to start or bind the service (read the blog post, Things That Cannot Change).\r\nCaution: To ensure that your app is secure, always use an explicit intent when starting a Service and don't\r\ndeclare intent filters for your services. Using an implicit intent to start a service is a security hazard because you\r\ncannot be certain of the service that responds to the intent, and the user cannot see which service starts. Beginning\r\nwith Android 5.0 (API level 21), the system throws an exception if you call bindService() with an implicit\r\nintent.\r\nYou can ensure that your service is available to only your app by including the android:exported attribute and\r\nsetting it to false . This effectively stops other apps from starting your service, even when using an explicit\r\nintent.\r\nNote: Users can see what services are running on their device. If they see a service that they don't recognize or\r\ntrust, they can stop the service. In order to avoid having your service stopped accidentally by users, you need to\r\nadd the android:description attribute to the \u003cservice\u003e element in your app manifest. In the description,\r\nprovide a short sentence explaining what the service does and what benefits it provides.\r\nCreating a started service\r\nA started service is one that another component starts by calling startService() , which results in a call to the\r\nservice's onStartCommand() method.\r\nWhen a service is started, it has a lifecycle that's independent of the component that started it. The service can run\r\nin the background indefinitely, even if the component that started it is destroyed. As such, the service should stop\r\nitself when its job is complete by calling stopSelf() , or another component can stop it by calling\r\nstopService() .\r\nAn application component such as an activity can start the service by calling startService() and passing an\r\nIntent that specifies the service and includes any data for the service to use. The service receives this Intent\r\nin the onStartCommand() method.\r\nFor instance, suppose an activity needs to save some data to an online database. The activity can start a companion\r\nservice and deliver it the data to save by passing an intent to startService() . The service receives the intent in\r\nonStartCommand() , connects to the Internet, and performs the database transaction. When the transaction is\r\ncomplete, the service stops itself and is destroyed.\r\nhttps://developer.android.com/guide/components/services.html#Foreground\r\nPage 4 of 14\n\nCaution: A service runs in the same process as the application in which it is declared and in the main thread of\r\nthat application by default. If your service performs intensive or blocking operations while the user interacts with\r\nan activity from the same application, the service slows down activity performance. To avoid impacting\r\napplication performance, start a new thread inside the service.\r\nThe Service class is the base class for all services. When you extend this class, it's important to create a new\r\nthread in which the service can complete all of its work; the service uses your application's main thread by default,\r\nwhich can slow the performance of any activity that your application is running.\r\nThe Android framework also provides the IntentService subclass of Service that uses a worker thread to\r\nhandle all of the start requests, one at a time. Using this class is not recommended for new apps as it will not\r\nwork well starting with Android 8 Oreo, due to the introduction of Background execution limits. Moreover, it's\r\ndeprecated starting with Android 11. You can use JobIntentService as a replacement for IntentService that is\r\ncompatible with newer versions of Android.\r\nThe following sections describe how you can implement your own custom service, however you should strongly\r\nconsider using WorkManager instead for most use cases. Consult the guide to background processing on Android\r\nto see if there is a solution that fits your needs.\r\nExtending the Service class\r\nYou can extend the Service class to handle each incoming intent. Here's how a basic implementation might\r\nlook:\r\nclass HelloService : Service() {\r\n private var serviceLooper: Looper? = null\r\n private var serviceHandler: ServiceHandler? = null\r\n // Handler that receives messages from the thread\r\n private inner class ServiceHandler(looper: Looper) : Handler(looper) {\r\n override fun handleMessage(msg: Message) {\r\n // Normally we would do some work here, like download a file.\r\n // For our sample, we just sleep for 5 seconds.\r\n try {\r\n Thread.sleep(5000)\r\n } catch (e: InterruptedException) {\r\n // Restore interrupt status.\r\n Thread.currentThread().interrupt()\r\n }\r\n // Stop the service using the startId, so that we don't stop\r\n // the service in the middle of handling another job\r\n stopSelf(msg.arg1)\r\n }\r\nhttps://developer.android.com/guide/components/services.html#Foreground\r\nPage 5 of 14\n\n}\r\n override fun onCreate() {\r\n // Start up the thread running the service. Note that we create a\r\n // separate thread because the service normally runs in the process's\r\n // main thread, which we don't want to block. We also make it\r\n // background priority so CPU-intensive work will not disrupt our UI.\r\n HandlerThread(\"ServiceStartArguments\", Process.THREAD_PRIORITY_BACKGROUND).apply {\r\n start()\r\n // Get the HandlerThread's Looper and use it for our Handler\r\n serviceLooper = looper\r\n serviceHandler = ServiceHandler(looper)\r\n }\r\n }\r\n override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {\r\n Toast.makeText(this, \"service starting\", Toast.LENGTH_SHORT).show()\r\n // For each start request, send a message to start a job and deliver the\r\n // start ID so we know which request we're stopping when we finish the job\r\n serviceHandler?.obtainMessage()?.also { msg -\u003e\r\n msg.arg1 = startId\r\n serviceHandler?.sendMessage(msg)\r\n }\r\n // If we get killed, after returning from here, restart\r\n return START_STICKY\r\n }\r\n override fun onBind(intent: Intent): IBinder? {\r\n // We don't provide binding, so return null\r\n return null\r\n }\r\n override fun onDestroy() {\r\n Toast.makeText(this, \"service done\", Toast.LENGTH_SHORT).show()\r\n }\r\n}\r\npublic class HelloService extends Service {\r\n private Looper serviceLooper;\r\n private ServiceHandler serviceHandler;\r\n // Handler that receives messages from the thread\r\n private final class ServiceHandler extends Handler {\r\nhttps://developer.android.com/guide/components/services.html#Foreground\r\nPage 6 of 14\n\npublic ServiceHandler(Looper looper) {\r\n super(looper);\r\n }\r\n @Override\r\n public void handleMessage(Message msg) {\r\n // Normally we would do some work here, like download a file.\r\n // For our sample, we just sleep for 5 seconds.\r\n try {\r\n Thread.sleep(5000);\r\n } catch (InterruptedException e) {\r\n // Restore interrupt status.\r\n Thread.currentThread().interrupt();\r\n }\r\n // Stop the service using the startId, so that we don't stop\r\n // the service in the middle of handling another job\r\n stopSelf(msg.arg1);\r\n }\r\n }\r\n @Override\r\n public void onCreate() {\r\n // Start up the thread running the service. Note that we create a\r\n // separate thread because the service normally runs in the process's\r\n // main thread, which we don't want to block. We also make it\r\n // background priority so CPU-intensive work doesn't disrupt our UI.\r\n HandlerThread thread = new HandlerThread(\"ServiceStartArguments\",\r\n Process.THREAD_PRIORITY_BACKGROUND);\r\n thread.start();\r\n // Get the HandlerThread's Looper and use it for our Handler\r\n serviceLooper = thread.getLooper();\r\n serviceHandler = new ServiceHandler(serviceLooper);\r\n }\r\n @Override\r\n public int onStartCommand(Intent intent, int flags, int startId) {\r\n Toast.makeText(this, \"service starting\", Toast.LENGTH_SHORT).show();\r\n // For each start request, send a message to start a job and deliver the\r\n // start ID so we know which request we're stopping when we finish the job\r\n Message msg = serviceHandler.obtainMessage();\r\n msg.arg1 = startId;\r\n serviceHandler.sendMessage(msg);\r\n // If we get killed, after returning from here, restart\r\n return START_STICKY;\r\n }\r\nhttps://developer.android.com/guide/components/services.html#Foreground\r\nPage 7 of 14\n\n@Override\r\n public IBinder onBind(Intent intent) {\r\n // We don't provide binding, so return null\r\n return null;\r\n }\r\n @Override\r\n public void onDestroy() {\r\n Toast.makeText(this, \"service done\", Toast.LENGTH_SHORT).show();\r\n }\r\n}\r\nThe example code handles all incoming calls in onStartCommand() and posts the work to a Handler running on\r\na background thread. It works just like an IntentService and processes all requests serially, one after another.\r\nYou could change the code to run the work on a thread pool, for example, if you'd like to run multiple requests\r\nsimultaneously.\r\nNotice that the onStartCommand() method must return an integer. The integer is a value that describes how the\r\nsystem should continue the service in the event that the system kills it. The return value from onStartCommand()\r\nmust be one of the following constants:\r\nSTART_NOT_STICKY\r\nIf the system kills the service after onStartCommand() returns, do not recreate the service unless there are\r\npending intents to deliver. This is the safest option to avoid running your service when not necessary and\r\nwhen your application can simply restart any unfinished jobs.\r\nSTART_STICKY\r\nIf the system kills the service after onStartCommand() returns, recreate the service and call\r\nonStartCommand() , but do not redeliver the last intent. Instead, the system calls onStartCommand() with\r\na null intent unless there are pending intents to start the service. In that case, those intents are delivered.\r\nThis is suitable for media players (or similar services) that are not executing commands but are running\r\nindefinitely and waiting for a job.\r\nSTART_REDELIVER_INTENT\r\nIf the system kills the service after onStartCommand() returns, recreate the service and call\r\nonStartCommand() with the last intent that was delivered to the service. Any pending intents are delivered\r\nin turn. This is suitable for services that are actively performing a job that should be immediately resumed,\r\nsuch as downloading a file.\r\nFor more details about these return values, see the linked reference documentation for each constant.\r\nStarting a service\r\nYou can start a service from an activity or other application component by passing an Intent to\r\nstartService() or startForegroundService() . The Android system calls the service's onStartCommand()\r\nmethod and passes it the Intent , which specifies which service to start.\r\nhttps://developer.android.com/guide/components/services.html#Foreground\r\nPage 8 of 14\n\nNote: If your app targets API level 26 or higher, the system imposes restrictions on using or creating background\r\nservices unless the app itself is in the foreground. If an app needs to create a foreground service, the app should\r\ncall startForegroundService() . That method creates a background service, but the method signals to the system\r\nthat the service will promote itself to the foreground. Once the service has been created, the service must call its\r\nstartForeground() method within five seconds.\r\nFor example, an activity can start the example service in the previous section ( HelloService ) using an explicit\r\nintent with startService() , as shown here:\r\nstartService(Intent(this, HelloService::class.java))\r\nstartService(new Intent(this, HelloService.class));\r\nThe startService() method returns immediately, and the Android system calls the service's onStartCommand()\r\nmethod. If the service isn't already running, the system first calls onCreate() , and then it calls\r\nonStartCommand() .\r\nIf the service doesn't also provide binding, the intent that is delivered with startService() is the only mode of\r\ncommunication between the application component and the service. However, if you want the service to send a\r\nresult back, the client that starts the service can create a PendingIntent for a broadcast (with getBroadcast() )\r\nand deliver it to the service in the Intent that starts the service. The service can then use the broadcast to deliver\r\na result.\r\nMultiple requests to start the service result in multiple corresponding calls to the service's onStartCommand() .\r\nHowever, only one request to stop the service (with stopSelf() or stopService() ) is required to stop it.\r\nStopping a service\r\nA started service must manage its own lifecycle. That is, the system doesn't stop or destroy the service unless it\r\nmust recover system memory and the service continues to run after onStartCommand() returns. The service must\r\nstop itself by calling stopSelf() , or another component can stop it by calling stopService() .\r\nOnce requested to stop with stopSelf() or stopService() , the system destroys the service as soon as possible.\r\nIf your service handles multiple requests to onStartCommand() concurrently, you shouldn't stop the service when\r\nyou're done processing a start request, as you might have received a new start request (stopping at the end of the\r\nfirst request would terminate the second one). To avoid this problem, you can use stopSelf(int) to ensure that\r\nyour request to stop the service is always based on the most recent start request. That is, when you call\r\nstopSelf(int) , you pass the ID of the start request (the startId delivered to onStartCommand() ) to which\r\nyour stop request corresponds. Then, if the service receives a new start request before you are able to call\r\nstopSelf(int) , the ID doesn't match and the service doesn't stop.\r\nCaution: To avoid wasting system resources and consuming battery power, ensure that your application stops its\r\nservices when it's done working. If necessary, other components can stop the service by calling stopService() .\r\nhttps://developer.android.com/guide/components/services.html#Foreground\r\nPage 9 of 14\n\nEven if you enable binding for the service, you must always stop the service yourself if it ever receives a call to\r\nonStartCommand() .\r\nFor more information about the lifecycle of a service, see the section below about Managing the Lifecycle of a\r\nService.\r\nCreating a bound service\r\nA bound service is one that allows application components to bind to it by calling bindService() to create a\r\nlong-standing connection. It generally doesn't allow components to start it by calling startService() .\r\nCreate a bound service when you want to interact with the service from activities and other components in your\r\napplication or to expose some of your application's functionality to other applications through interprocess\r\ncommunication (IPC).\r\nTo create a bound service, implement the onBind() callback method to return an IBinder that defines the\r\ninterface for communication with the service. Other application components can then call bindService() to\r\nretrieve the interface and begin calling methods on the service. The service lives only to serve the application\r\ncomponent that is bound to it, so when there are no components bound to the service, the system destroys it. You\r\ndo not need to stop a bound service in the same way that you must when the service is started through\r\nonStartCommand() .\r\nTo create a bound service, you must define the interface that specifies how a client can communicate with the\r\nservice. This interface between the service and a client must be an implementation of IBinder and is what your\r\nservice must return from the onBind() callback method. After the client receives the IBinder , it can begin\r\ninteracting with the service through that interface.\r\nMultiple clients can bind to the service simultaneously. When a client is done interacting with the service, it calls\r\nunbindService() to unbind. When there are no clients bound to the service, the system destroys the service.\r\nThere are multiple ways to implement a bound service, and the implementation is more complicated than a started\r\nservice. For these reasons, the bound service discussion appears in a separate document about Bound Services.\r\nSending notifications to the user\r\nWhen a service is running, it can notify the user of events using snackbar notifications or status bar notifications.\r\nA snackbar notification is a message that appears on the surface of the current window for only a moment before\r\ndisappearing. A status bar notification provides an icon in the status bar with a message, which the user can select\r\nin order to take an action (such as start an activity).\r\nUsually, a status bar notification is the best technique to use when background work such as a file download has\r\ncompleted, and the user can now act on it. When the user selects the notification from the expanded view, the\r\nnotification can start an activity (such as to display the downloaded file).\r\nManaging the lifecycle of a service\r\nhttps://developer.android.com/guide/components/services.html#Foreground\r\nPage 10 of 14\n\nThe lifecycle of a service is much simpler than that of an activity. However, it's even more important that you pay\r\nclose attention to how your service is created and destroyed because a service can run in the background without\r\nthe user being aware.\r\nThe service lifecycle—from when it's created to when it's destroyed—can follow either of these two paths:\r\nA started service\r\nThe service is created when another component calls startService() . The service then runs indefinitely\r\nand must stop itself by calling stopSelf() . Another component can also stop the service by calling\r\nstopService() . When the service is stopped, the system destroys it.\r\nA bound service\r\nThe service is created when another component (a client) calls bindService() . The client then\r\ncommunicates with the service through an IBinder interface. The client can close the connection by\r\ncalling unbindService() . Multiple clients can bind to the same service and when all of them unbind, the\r\nsystem destroys the service. The service does not need to stop itself.\r\nThese two paths aren't entirely separate. You can bind to a service that is already started with startService() .\r\nFor example, you can start a background music service by calling startService() with an Intent that\r\nidentifies the music to play. Later, possibly when the user wants to exercise some control over the player or get\r\ninformation about the current song, an activity can bind to the service by calling bindService() . In cases such as\r\nthis, stopService() or stopSelf() doesn't actually stop the service until all of the clients unbind.\r\nImplementing the lifecycle callbacks\r\nLike an activity, a service has lifecycle callback methods that you can implement to monitor changes in the\r\nservice's state and perform work at the appropriate times. The following skeleton service demonstrates each of the\r\nlifecycle methods:\r\nclass ExampleService : Service() {\r\n private var startMode: Int = 0 // indicates how to behave if the service is killed\r\n private var binder: IBinder? = null // interface for clients that bind\r\n private var allowRebind: Boolean = false // indicates whether onRebind should be used\r\n override fun onCreate () {\r\n // The service is being created\r\n }\r\n override fun onStartCommand (intent: Intent?, flags: Int, startId: Int): Int {\r\n // The service is starting, due to a call to startService()\r\n return startMode\r\n }\r\n override fun onBind (intent: Intent): IBinder? {\r\nhttps://developer.android.com/guide/components/services.html#Foreground\r\nPage 11 of 14\n\n// A client is binding to the service with bindService()\r\n return binder\r\n }\r\n override fun onUnbind (intent: Intent): Boolean {\r\n // All clients have unbound with unbindService()\r\n return allowRebind\r\n }\r\n override fun onRebind (intent: Intent) {\r\n // A client is binding to the service with bindService(),\r\n // after onUnbind() has already been called\r\n }\r\n override fun onDestroy () {\r\n // The service is no longer used and is being destroyed\r\n }\r\n}\r\npublic class ExampleService extends Service {\r\n int startMode; // indicates how to behave if the service is killed\r\n IBinder binder; // interface for clients that bind\r\n boolean allowRebind; // indicates whether onRebind should be used\r\n @Override\r\n public void onCreate () {\r\n // The service is being created\r\n }\r\n @Override\r\n public int onStartCommand (Intent intent, int flags, int startId) {\r\n // The service is starting, due to a call to startService()\r\n return startMode;\r\n }\r\n @Override\r\n public IBinder onBind (Intent intent) {\r\n // A client is binding to the service with bindService()\r\n return binder;\r\n }\r\n @Override\r\n public boolean onUnbind (Intent intent) {\r\n // All clients have unbound with unbindService()\r\n return allowRebind;\r\n }\r\n @Override\r\n public void onRebind (Intent intent) {\r\n // A client is binding to the service with bindService() ,\r\nhttps://developer.android.com/guide/components/services.html#Foreground\r\nPage 12 of 14\n\n// after onUnbind() has already been called\r\n }\r\n @Override\r\n public void onDestroy () {\r\n // The service is no longer used and is being destroyed\r\n }\r\n}\r\nNote: Unlike the activity lifecycle callback methods, you are not required to call the superclass implementation of\r\nthese callback methods.\r\nFigure 2. The service lifecycle. The diagram on the left shows the lifecycle when the service is created with\r\nstartService() and the diagram on the right shows the lifecycle when the service is created with\r\nbindService() .\r\nFigure 2 illustrates the typical callback methods for a service. Although the figure separates services that are\r\ncreated by startService() from those created by bindService() , keep in mind that any service, no matter\r\nhow it's started, can potentially allow clients to bind to it. A service that was initially started with\r\nonStartCommand() (by a client calling startService() ) can still receive a call to onBind() (when a client\r\ncalls bindService() ).\r\nhttps://developer.android.com/guide/components/services.html#Foreground\r\nPage 13 of 14\n\nBy implementing these methods, you can monitor these two nested loops of the service's lifecycle:\r\nThe entire lifetime of a service occurs between the time that onCreate() is called and the time that\r\nonDestroy() returns. Like an activity, a service does its initial setup in onCreate() and releases all\r\nremaining resources in onDestroy() . For example, a music playback service can create the thread where\r\nthe music is played in onCreate() , and then it can stop the thread in onDestroy() .\r\nNote: The onCreate() and onDestroy() methods are called for all services, whether they're created by\r\nstartService() or bindService() .\r\nThe active lifetime of a service begins with a call to either onStartCommand() or onBind() . Each\r\nmethod is handed the Intent that was passed to either startService() or bindService() .\r\nIf the service is started, the active lifetime ends at the same time that the entire lifetime ends (the service is\r\nstill active even after onStartCommand() returns). If the service is bound, the active lifetime ends when\r\nonUnbind() returns.\r\nNote: Although a started service is stopped by a call to either stopSelf() or stopService() , there isn't a\r\nrespective callback for the service (there's no onStop() callback). Unless the service is bound to a client, the\r\nsystem destroys it when the service is stopped— onDestroy() is the only callback received.\r\nFor more information about creating a service that provides binding, see the Bound Services document, which\r\nincludes more information about the onRebind() callback method in the section about Managing the lifecycle of\r\na bound service.\r\nSource: https://developer.android.com/guide/components/services.html#Foreground\r\nhttps://developer.android.com/guide/components/services.html#Foreground\r\nPage 14 of 14",
	"extraction_quality": 1,
	"language": "EN",
	"sources": [
		"MITRE"
	],
	"origins": [
		"web"
	],
	"references": [
		"https://developer.android.com/guide/components/services.html#Foreground"
	],
	"report_names": [
		"services.html#Foreground"
	],
	"threat_actors": [
		{
			"id": "75108fc1-7f6a-450e-b024-10284f3f62bb",
			"created_at": "2024-11-01T02:00:52.756877Z",
			"updated_at": "2026-04-10T02:00:05.273746Z",
			"deleted_at": null,
			"main_name": "Play",
			"aliases": null,
			"source_name": "MITRE:Play",
			"tools": [
				"Nltest",
				"AdFind",
				"PsExec",
				"Wevtutil",
				"Cobalt Strike",
				"Playcrypt",
				"Mimikatz"
			],
			"source_id": "MITRE",
			"reports": null
		}
	],
	"ts_created_at": 1775441479,
	"ts_updated_at": 1775826773,
	"ts_creation_date": 0,
	"ts_modification_date": 0,
	"files": {
		"pdf": "https://archive.orkl.eu/790ee104c446c06ab96bd650653b242662aea0f6.pdf",
		"text": "https://archive.orkl.eu/790ee104c446c06ab96bd650653b242662aea0f6.txt",
		"img": "https://archive.orkl.eu/790ee104c446c06ab96bd650653b242662aea0f6.jpg"
	}
}