By using the below code, I'm trying to start new service from a Broadcast receiver
, but the service does not seem to start. What is the correct way to start a service in kotlin?
val intent = Intent(context, LocationService::class.java)
if (context != null) {
context.startService(intent)
}
try this
val intent = Intent(context, LocationService::class.java)
if (context != null) {
context.startService(intent)
}
And don't forget to register your service
in manifest
file
<service android:name="packageName.LocationService"/>
Put declaration of service in AndroidManifest.xml file
i.e <service android:name=".LocationService"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With