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 com.android.vending.INSTALL_REFERRER -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

Others

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏技术点滴

Windows注册表操作基础代码

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

2099
来自专栏H2Cloud

Tips for thrift

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

3575
来自专栏西二旗一哥

React-native - Install & Lauch & Filling Holes

771
来自专栏everhad

转载:Package by feature, not layer

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

1240
来自专栏Kubernetes

kube-controller-manager最佳配置

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

4789
来自专栏大数据学习笔记

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

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

2685
来自专栏一个会写诗的程序员的博客

$ 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 ...

1142
来自专栏Albert陈凯

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

1322
来自专栏Android 开发学习

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

4153
来自专栏Linyb极客之路

你该怎么做?当你发现springboot扫描controller没有生效

加上@SpringBootApplication为啥就能扫描到,其实我也不知道。那就看下这个注解到底是个啥样的奇葩,它的注解构造了解一下

3.7K3

扫码关注云+社区

领取腾讯云代金券