如果你的编译SDK版本在API20 以下 你可以使用一般的隐式调用方式打开新的service
//下面intent构造方法内的参数是action对象的名称
Intent intent = new Intent("org.allin.android.musicService");
startService(intent);
现在SDK版本已经更新到API24了,对于最新SDK上面给定的方法不适用了
Intent intent = new Intent();
intent.setAction("org.allin.android.musicService");//你定义的service的action
intent.setPackage(getPackageName());//这里你需要设置你应用的包名
startService(intent);
本文介绍了如何根据不同的Android SDK版本适配启动Service的方法。对于API20以下的版本,可以直接通过Intent构造方法启动Service;而对于API24及更高版本,则需通过设置Action和包名来启动。
2928

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



