Log*_*ogo 9 android kotlin android-components
通过使用下面的代码,我试图从启动新服务Broadcast receiver
,但该服务未启动。请指导我如何在中启动服务kotlin
。
val intent = Intent(context, LocationService::class.java)
if (context != null) {
context.startService(intent)
}
Run Code Online (Sandbox Code Playgroud)
尝试这个
val intent = Intent(context, LocationService::class.java)
if (context != null) {
context.startService(intent)
}
Run Code Online (Sandbox Code Playgroud)
而且不要忘记service
在manifest
文件中注册
<service android:name="packageName.LocationService"/>
Run Code Online (Sandbox Code Playgroud)
在 kotlin 中使用安全访问压缩:
val intent = Intent(context, LocationService::class.java)
context?.startService(intent)
Run Code Online (Sandbox Code Playgroud)
还要在您的清单中定义您的服务。
归档时间: |
|
查看次数: |
7263 次 |
最近记录: |