前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Package Stopped State Since Android 3.1

Package Stopped State Since Android 3.1

作者头像
技术小黑屋
发布2018-09-04 16:32:38
7730
发布2018-09-04 16:32:38
举报

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

  • Programming Android: Java Programming for the New Generation of Mobile Devices
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • First Bite
    • What is Stopped State
      • Why Android Adds this
      • State Switch from/to Stopped State
        • To Stopped Sate
          • To Normal State (Not Stopped)
          • Send Broadcast Intent to Stopped Packages
          • Check Package Stopped
          • special Issues
          • Referrences Links
            • Others
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档