Android用Intent来启动Service报“java.lang.IllegalArgumentException: Service Intent must be explicit”错误的解决方法

  今天没事来写个播放器,照搬书上的原句,其中一句

     //用于启动和停止service的Intent
        final Intent it = new Intent("android.mu.action.music");

  在运行的时候就出了问题,经百度,是Android5.0以后不能这么写了,所以挂了(看来书要读新啊,技术变化太快,旧书过时了)。

  那么该怎么改?

        //用于启动和停止service的Intent
        final Intent it = new Intent(当前类名.this,要调用的Service类名.class);    

  这样显式声明就可以了。

  再运行,OK。