‫The other type is start not sticky.
‫If you return, start not sticky, it indicates that the service should not be restarted by the system
‫after it has been terminated.
‫This service will remain stopped unless explicitly started again by the application or the component.
‫This return type is suitable for services that perform specific tasks and don't need to be running continuously.
‫For example, a service that plays a sound effect when a notification is received might use this option.
‫And there are a lot of other modes like started redeliver intent start to sticky compatibility and others.
‫But the main two types is start not sticky and start sticky.
‫I'll use start sticky.
‫Now I need to override another callback method called Ondestroy.
‫The execution of the service will stop on calling this method.
‫The Ondestroy.
‫I need to stop the process.
‫So player player dot stop.
‫I need to stop the music in Android.
‫The unbind method is a part of the service class and is used specifically in the context of bound services.
‫A bound service is a type of service that allows other components, usually activities to bind to it
‫and interact with it by obtaining an I binder interface.
‫And the I binder interface is used to establish a communication channel between the components and the
‫service if you return null.
‫And this is the default implementation, this indicates that the service doesn't support binding and
‫therefore cannot be bound to.
‫In this example, I will not bind any activity to this service.
‫We created my custom service class and we need to start the music and perform the operation to start
‫this service.
‫I'll go to the main activity start button, dot set on Click Listener, New view and click Listener.
‫And I need to pass here the logic that allows us to start the custom service.
‫I'll call a method called Start service.
‫The start service method is used to initiate the execution of a service.
‫It's a way to start a service independently of other components and allows the service to perform background
‫tasks or operations, even if the initialization component is paused or destroyed.
‫The start service method is used to start an unbound service.
‫To start the service you call the start service method passing an intent that the specifies which service
‫you want to start, which is typically done from within an activity, broadcast receiver or other application
‫component.
‫So for that I need to create an intent object.
‫Alt+ enter to import the intent package.
‫I name it as service intent equal to new intent and I need to pass the context, get application context
‫as the first parameter.
‫And the second parameter is the service class.
‫My custom service dot class when we created the intents and use it to navigate between different components
‫and different activities, We pass the name of the activity here and we call the method start activity.
‫But here I'm using service, so I'm calling this service start service method and I need to use the
‫intent to use the service the same way.
‫I need to use the stop button set on click listener, you and click listener and I'll create or use
‫a method called stop service in the same way before I'll copy this intent to use this method, my custom
‫service and I need to stop this service intent.
‫Let's save the project, run the application and if we click on the buttons, nothing happens because
‫we didn't implement the service in the manifest to implement the services successfully on any Android
‫device, it's necessary to mention the created service in Androidmanifest.xml file because it's a component.
‫We need to mention it inside the manifest file.
‫So here you can see I mentioned the activity.
‫So we have only one activity.
‫I'll collapse it by clicking on this button here under the activity and inside the application tag,
‫I need to define the service.
‫It's not possible for a service to perform its task if it is not mentioned in this file, the service
‫name is mentioned inside.
‫The application tag.
‫So I'll use service.
‫And here I need to mention the name of my service, my custom service, and I'll use the closing tag
‫for this service name.
‫So you should mention the service as a tag in the Android manifest file.
‫Let's run the application again and this is our application Click Start service and you can hear the
‫sound of the ringtone.
‫It's played continuously, and if you click on the home and you skip the application, you can see it's
‫still running and making this sound, playing the audio sound.