美文网首页Android开发经验谈Android知识
Android 5.0 禁止使用隐式Intent来启动Servi

Android 5.0 禁止使用隐式Intent来启动Servi

作者: _ming_ming | 来源:发表于2016-07-27 22:55 被阅读182次

intentService

听说,intentService可以避免OOM异常,而且省去了在Service中手动开线程的麻烦,第二,当操作完成时,我们不用手动停止Service。
吓得我赶紧写了个Demo试试看。
结果报了error,又是个bug。发现Android一天不给你几个bug,你就浑身发痒是不。

正好下了个源码,

    private void validateServiceIntent(Intent service) {
        if (service.getComponent() == null && service.getPackage() == null) {
            if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP) {
                IllegalArgumentException ex = new IllegalArgumentException(
                        "Service Intent must be explicit: " + service);
                throw ex;
            } else {
                Log.w(TAG, "Implicit intents with startService are not safe: " + service
                        + " " + Debug.getCallers(2, 3));
            }
        }
    }
```
* 大概意思是你api>21,你就不能隐式调用Service。

* 四下搜寻,get好博文。

>http://blog.csdn.net/qq979418391/article/details/50624304

#### 侵权必删

相关文章

网友评论

    本文标题:Android 5.0 禁止使用隐式Intent来启动Servi

    本文链接:https://www.haomeiwen.com/subject/pwtajttx.html