Package Stopped State Since Android 3.1

First Bite

Since Android 3.1, Android has introduced a LaunchControl mechanism. It’s call Stopped State.

Here is what Google describes

What is Stopped State

Starting from Android 3.1, the system’s package manager keeps track of applications that are in a stopped state and provides a means of controlling their launch from background processes and other applications. Note that an application’s stopped state is not the same as an Activity’s stopped state. The system manages those two stopped states separately.

Why Android Adds this

Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcast intents. It does this to prevent broadcasts from background services from inadvertently or unnecessarily launching components of stoppped applications. A background service or application can override this behavior by adding the FLAG_INCLUDE_STOPPED_PACKAGES flag to broadcast intents that should be allowed to activate stopped applications.

As the above references point out it will prevent broadcast intents delivering to stopped packages. Actually this control mechanism will ensure safety and save energy.

State Switch from/to Stopped State

What Google says

Applications are in a stopped state when they are first installed but are not yet launched and when they are manually stopped by the user (in Manage Applications).

To Stopped Sate

  • Manually force-stop in Manage Application of Settings.
  • adb shell am force-stop package-name
  • Use Hidden Method ActivityManager.forceStopPackages(String packageName) with Right Permission <uses-permission android:name=“android.permission.FORCE_STOP_PACKAGES”/> It’s without test.

To Normal State (Not Stopped)

  • Manually Launch your application.
  • Use adb to Activate components(Activity or Receiver ) of the application

Send Broadcast Intent to Stopped Packages

The platform defines two new intent flags that let a sender specify whether the Intent should be allowed to activate components in stopped application. FLAG_INCLUDE_STOPPED_PACKAGES — Include intent filters of stopped applications in the list of potential targets to resolve against. FLAG_EXCLUDE_STOPPED_PACKAGES — Exclude intent filters of stopped applications from the list of potential targets. When neither or both of these flags is defined in an intent, the default behavior is to include filters of stopped applications in the list of potential targets.

  • Add your Intent Flag FLAG_INCLUDE_STOPPED_PACKAGES in Java
  • Use ADB with Flag FLAG_INCLUDE_STOPPED_PACKAGES such as adb shell am broadcast -a -f 32

Check Package Stopped

  • Manually Check InstalledAppDetails in Manage applications of Settings.
  • Step into Terminal of the Device and cat /data/system/packages-stopped.xml

special Issues

  • Q:If My application has no activities and it just has a receiver, How can I activate and receive common broadcast intents?
  • A:Actually your above application is actually Not Stopped State when it’s first installed. Becuase It has no launcher clickable chance. It can receive normal broadcast smoothly If you do not manually force-stop it.
  • Q:Will the system application be in stopped state when it’s first installed?
  • A:The apps located in /system/app are what we called System Applications. It’s Not in stopped state when it’s installed.
  • Q:Will Google Play App still sends campaign broadcast to my application to keep track of install referrers?
  • A:Actually It does work smoothly. And I have tested on 4.0 OS device. I think the Play Store App adds FLAG_INCLUDE_STOPPED_PACKAGES to the broadcast intent.

Referrences Links





0 条评论
登录 后参与评论




Windows注册表操作基础代码     Windows下对注册表进行操作使用的一段基础代码Reg.h: #pragma once #include<asser...


Tips for thrift

Introduction I have designed and developed game servers successfully with thrift...


React-native - Install & Lauch & Filling Holes


转载:Package by feature, not layer

The first question in building an application is "How do I divide it up into pac...



kubernetes version: 1.6.2 Kube-controller-manager Configuration kube-controller-...


Hadoop基础教程-第9章 HA高可用(9.3 HDFS 高可用运行)(草稿)

第9章 HA高可用 9.3 HDFS 高可用运行 9.3.1 HA节点规划 节点 IP Zookeeper NameNode JournalNode Da...


$ gradle packageDebug --stacktrace error: top-left corner pixel must be either opaque white or trans

$ gradle packageDebug --stacktrace error: top-left corner pixel must be either ...


2018-11-06 openhub.net开源项目。

来自专栏Android 开发学习

Android studio 2.2 JNI ffmpeg 简单的播放器(这里只有视频解码)include "libavcodec/avcodec.h"include "libavformat/avf