隐式启动:(通过设置包名和action启动)
component代码需要添加包名和service名:
Intent intent = new Intent();
ComponentName componentName = new ComponentName(getPackageName(), "com.example.testservices.TestService");
intent.setComponent(componentName);
startService(intent);
对应的manifes代码,需要添加action:
显示启动: java代码直接指明启动的service:
Intent intent = new Intent(this, TestService.class);
startService(intent);
AndroidManifest代码不需要特殊配置:
可以参考博客:https://blog.csdn.net/liuyi1207164339/article/details/51711435