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"/>