您的位置:首页 > 其它

Service Intent must be explicit--服务的intent必须使用显示传递

2016-05-11 00:00 375 查看
就在我庆幸这次完成了按字母顺序排列音乐,自定义扫描手机中的音乐两个功能后,准备更新博客,那就发张截图给大家看看我做出来的效果吧!然后发现了BUG

。音乐不能播放了!!!事态很严重,立马查找是不是哪的代码被我修改错了,debug一下,流程正常。把报错内容java.lang.IllegalArgumentException: Service Intent must be explicit贴出来查了下原来是前一天我把我手机系统升级到5.0的原因!!


Android 5.0 需要显性调用 Service


于是乎就把Intent修改成显式传递

原来是这么写:

Intent intent = new Intent();
intent.setAction("com.app.media.music_service");
intent.putExtra("idOption", myPosition);
startService(intent);


修改后这么写:

Intent intent = new Intent(MainActivity.this,MusicService.class);
intent.setAction("com.app.media.music_service");
intent.putExtra("idOption", myPosition);
startService(intent);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: