Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kotlin android start new service

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)
 }
like image 742
Logo Avatar asked Aug 09 '17 08:08

Logo


2 Answers

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"/>
like image 131
AskNilesh Avatar answered Sep 16 '22 16:09

AskNilesh


Put declaration of service in AndroidManifest.xml file
i.e <service android:name=".LocationService"/>

like image 37
mac229 Avatar answered Sep 18 '22 16:09

mac229