---
title: "Android系统中STOPPED应用无法接收广播的研究"
author: "OliveExcel"
date: "2016-06-08T19:08:34Z"
tags: []
categories: ["移动开发"]
slug: "android-stopped"
draft: true
lastmod: "2016-06-08T19:08:34Z"
id: 2304103
url: "https://oliveexcel.iteye.com/blog/2304103"
---

**之前写过一篇文章:** 

### [Android 3.1后, 新安装的以及用户强行停止的apk, 无法监听广播的问题](/admin/blogs/1969265)

 

**今天终于研究了一下原理, 把代码执行逻辑贴上来:**

```
ContextImpl.sendBroadcast()
    ActivityManagerNative.getDefault().broadcastIntent()
        ActivityManagerService.broadcastIntent()
            ActivityManagerService.broadcastIntentLocked()
                ActivityManagerService.collectReceiverComponents()
                    PackageManagerService.queryIntentReceivers()
                        PackageManagerService.ActivityIntentResolver.queryIntentForPackage()
                            IntentResolver.queryIntentFromList()
                                IntentResolver.buildResolveList()
                                    PackageManagerService.ActivityIntentResolver.isFilterStopped()
                                        return (ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0 && ps.getStopped(userId);
```

 

**结论:** 

只有非STOPPED状态的应用, 以及系统应用, 可以接收到Intent中不包含[FLAG\_INCLUDE\_STOPPED\_PACKAGES](http://developer.android.com/reference/android/content/Intent.html#FLAG_INCLUDE_STOPPED_PACKAGES)的广播.