假设应用A中的myActivity,想要调用应用B的myService
1.myActivity的调用代码:
Intent intent=new Intent(Intent.ACTION_MAIN);
//com.example.cat.myapplication为包名,com.example.cat.myapplication.MyService为包名加服务myService的类名 ComponentName cn=new ComponentName("com.example.cat.myapplication","com.example.cat.myapplication.MyService"); intent.setComponent(cn); startService(intent);
2.myService的注册代码:
下面两个是必须要开启的:android:enabled 和 android:exported。
<service android:name=".MyService" android:enabled="true" android:exported="true" > </service>


被折叠的 条评论
为什么被折叠?



