The stop state of the program in Android is described in detail _android

Source: Internet
Author: User
Tags new set

A lot of people have encountered the issue of broadcast, such as Google Play to promote the installation of radio did not receive, such as these questions, and what is the reason for this article will be answered.

Starting with the Android 3.1 (Honeycomb), API 12, Android introduces a new set of startup controls, which is the stop state of the program. Let's take a look at Google's description of the stop state of the program.

What is the stop state of a program

Copy Code code as follows:

Starting from Android 3.1, the system's package manager keeps track of applications that are to a stopped state and provid Es a means of controlling their launch from background processes and other applications.

Starting with Android 3.1, the system's Package Manager starts tracking programs that process the stop state. and provides methods to control the startup of them from background processes or other programs.

Note This application ' s stopped state isn't the same as activity ' s stopped state. The system manages those two stopped states separately.

Note that the program's stop state differs from the activity's stop state, and the system handles both states separately.

The platform defines two new intent flags so let a sender specify whether the intent should is allowed to activate Nents in stopped application. The Android platform provides two intent flags to allow the party sending the broadcast to decide whether the broadcast needs to be sent to a program that has been stopped at the same time.

Flag_include_stopped_packages-include Intent filters of STOPPED applications in the list of potential targets to resolve Against. Add already-supported programs to target handlers who can handle intent.

Flag_exclude_stopped_packages-exclude Intent filters of STOPPED applications from the list of potential targets. A program that has stopped is not included in the target processor that can handle intent.


If the above two flag are not in the intnet or set, the target processor contains the program that is already stopped. But note that the system adds flag_exclude_stopped_packages to the flag for all broadcast intent.

Why does Android have to introduce this state

Copy Code code as follows:

This is 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 St oppped applications. A background service or application can override this behavior by adding the Flag_include_stopped_packages FLAG to BROADCA St intents that should is allowed to activate stopped applications.

It is important to note that the system adds a flag_exclude_stopped_packages flag to all broadcast intent by default, in order to prevent inadvertent broadcasts from the background service or to start unnecessary components of a program that is in a stopped state.

The usual intnet broadcast, the receiver of the program in the stop state is unacceptable. So how do you get these stop-state programs to accept? You can do this by adding a flag_include_stopped_ when you send a broadcast in a background service or application PACKAGES flag, meaning a program that contains a stop state. This activates the Stop state program.

As noted in the above reference, the system defaults to prevent broadcast intent from being sent to a stop-state package, which is actually meant to be safe and power-saving. For example, the broadcast of network changes, if some programs registered to monitor, and it was broadcast, do a series of network operations, this is necessarily a very energy-consuming.

Toggle between activation state and stop state

The program is stopped when the program is first installed and does not start, or when the user stops the program by manually managing it.

How to become a stop state

1. Application details in Settings Application Management page Click Force Stop
2. Use adb shell adb shell am force-stop package-name
3. Use the Activitymanager hidden method forcestoppackages, and add the request permission to manifest <uses-permission android:name= " Android.permission.FORCE_STOP_PACKAGES "/>

How to get out of a stop state

1. Manually start the program
2. Use ADB to activate application components, such as activity or receiver

Send broadcast intent to the application in the Stop state

1. In the Java code when sending intent, add FLAG flag_include_stopped_packages
2. If the ADB is used, the same is added flag_include_stopped_packages (its specific value is 32), such as ADB shell am broadcast-a com.android.vending.INSTALL_ Referrer-f 32

Check to see if it is in a stopped state

1. Enter settings-Application management-a detailed page of an application that indicates that the program is already in a stopped state if the Force Stop button is not available.
2. Access to equipment terminals, view system files Cat/data/system/packages-stopped.xml

Question and answer session

Question: If my program has no activity and only one receiver, how can I activate to receive a normal broadcast intent?

Answer: In fact, if it is the case described above, the application is not stopped after installation because it does not have any user's direct click behavior to remove it from the stop state. You can normally receive radio intent unless you force it to stop artificially.

Question: System program just installed will be in a stop state?

Answer: The system's programs are usually stored in the/system/app directory and will not be stopped after the initial installation.

Question: Google Play's promotional broadcast is said to be sent after the installation of the program is completed, is not affected after 3.1

Answer: not affected. Google Docs said Install_referrer will be sent after the program is installed, according to the actual viewing log observations, from 3.1, after the program is installed the first time to open the send.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.