Service 从不同的包启动Android服务

Service 从不同的包启动Android服务,service,Service,当服务代码位于与主应用程序MainActivity不同的另一个包中时,我似乎无法启动android服务 我已经尝试了很多方法,甚至是AIDL方法,但我根本无法让它发挥作用 主活动代码 ServiceIntent.setComponent(new ComponentName("com.service.luna","com.service.luna.VService" )); bindService(ServiceIntent, mServiceConnection, Context.BIND_AU

当服务代码位于与主应用程序MainActivity不同的另一个包中时,我似乎无法启动android服务

我已经尝试了很多方法,甚至是AIDL方法,但我根本无法让它发挥作用

主活动代码

ServiceIntent.setComponent(new ComponentName("com.service.luna","com.service.luna.VService" ));
bindService(ServiceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
主要活动舱单

<?xml version="1.0" encoding="utf-8"?>

服务清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.service.luna">

<application
    android:allowBackup="true"
    android:label="@string/app_name"
    android:supportsRtl="true">


</application>
主包的名称为com.main.luna,服务位于包com.service.luna中


如果以前有人解决过这个问题,请告诉我。

在添加服务时,尝试在清单中启用导出选项(android:exported=“true”)


. . .
并确保您使用的是正确的包名

也检查一下这个帖子有类似的情况


如果您查看main清单中的我的服务标签,它已经在那里了。不起作用。可能问题出在您的服务代码中,使其无法启动。我使用该服务代码有一段时间了,而且在我决定将其移动到另一个软件包以使其更模块化之前,该代码一直在工作。我只是想知道这个问题的解决办法。我在任何地方都找不到解决方案。你能检查一下这个链接吗:我解决了这个延迟…那就是谷歌android开发。我必须在mainactivity包中以ServiceIntent.setComponent(新组件名(“com.main.luna”、“com.service.luna.VService”))的形式启动intent;这已经在你上面的原始帖子中了-除非你编辑了afterwardssolved?请发布ans,因为其他人可能也会得到帮助。。。
public class VService extends Service implements Serializable{
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.service.luna">

<application
    android:allowBackup="true"
    android:label="@string/app_name"
    android:supportsRtl="true">


</application>
bindService callerProcessName:com.main.luna, calleePkgName: com.service.luna, action: null
Unable to start service Intent { pkg=com.service.luna cmp=com.service.luna/.VService } U=0: not found
  <service android:enabled=["true" | "false"]
     android:exported=["true" | "false"]
     android:icon="drawable resource"
     android:isolatedProcess=["true" | "false"]
     android:label="string resource"
     android:name="string"
     android:permission="string"
     android:process="string" >
. . .
  </service>