android 开启service

来源:互联网 发布:老是找不到东西知乎 编辑:程序博客网 时间:2024/04/30 14:22

如果你的编译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);
0 0
原创粉丝点击