占位式插件化二Service的启动
系列文章 占位式插件化一Activity的跳转 占位式插件化的本质,就是用代理Activity或者Service使用插件app中的资源或者方法,从而达到执行插件APP的目的。 仿照Activity的跳转,可以知道启动插件APP中的Service,需要新增以下几个类,ServiceInterface做协议支持,BaseService实现ServiceInterface接口,ProxyService在宿主APP中占位,通过ProxyService即可启动插件APP中的Service,与其说启动了插件APP中的Service,不如说调用了插件APP中Service的方法。这时候插件APP中的Service也就只是一个普通的类,而不是安卓的四大组件之一的Service。 接口协议 public interface ServiceInterface { void insertAppService(Service appService); int onStartCommand(Intent intent, int flags, int startId); void onCreate(); } 插件APP的BaseService public class BaseService implements ServiceInterface { protected Service appService;