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

  • 2020-06-12 10:35:04
  • OfStack

Many people have encountered the problem of radio reception, such as Google Play promotion installation radio did not receive, etc., such as these questions, and what are the reasons? This article will answer.

Starting with Android 3.1(HoneyComb) or API 12,Android introduces a new set of startup controls, which are called the stop state of the program.

What is the stopped state of the program


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. from Android 3.1 start , The system's package manager starts tracking programs that handle stopped states . Methods are provided to control how background processes or other programs start them . 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. Pay attention to The stop state of the program and Activity The stop state is different , The system will handle these two states separately . The platform defines two new intent flags that let a sender specify whether the Intent should be allowed to activate components in stopped application. Android The platform provides two intent flags, Used to send a broadcast 1 The party decides whether the broadcast needs to be simultaneously sent to the stopped program . FLAG_INCLUDE_STOPPED_PACKAGES - Include intent filters of stopped applications in the list of potential targets to resolve against. Adds an already supported program to the processor intent Target handler for . FLAG_EXCLUDE_STOPPED_PACKAGES - Exclude intent filters of stopped applications from the list of potential targets. In can deal with intent The target handler for. Does not contain a stopped program .

If the above flag is not in intnet or set, the target handler contains the stopped program, but note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcast intent.

Why does Android introduce this 1 state


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.

It is important to note that by default, the system adds an FLAG_EXCLUDE_STOPPED_PACKAGES flag to all broadcast intent, in order to prevent careless broadcasting from background services or starting unnecessary components of a stopped program.

In the usual intnet broadcast, receiver of a stopped program is not acceptable. So how can these stopped programs be accepted? You can do this by adding an FLAG_INCLUDE_STOPPED_PACKAGES flag when broadcasting in a background service or application, which means that the application is in the stopped state. This will enable the stopped application.

As the reference point out, the system default block radio intent send packages in a stop state, in fact this is to ensure the safety and save electricity needs. Such as network changes the radio, if some application registers to monitor, and it by the radio, do a series of network operation, it must be very energy.

Switching between active state and stopped state

When the program is installed the first time and does not start, or when the user stops it manually from program management, the program is stopped.

How do I get to a stop state

1. Click Force Stop in the Application Details page of Setup Application Management
2. Use adb shell adb am ES61en-ES62en ES63en-ES64en
3. Use forceStopPackages, the hidden method of ActivityManager, and add permission to manifest < uses - permission android: name = "android. permission. FORCE_STOP_PACKAGES" / >

How do I get out of a stop state

1. Start the program manually
2. Use adb to activate application components such as activity or receiver

Send the broadcast intent to the stopped application

1. Add flag FLAG_INCLUDE_STOPPED_PACKAGES when Java code sends Intent
2. If you use adb, is also to join FLAG_INCLUDE_STOPPED_PACKAGES (the specific value of 32), such as adb shell am broadcast - a com. android. vending. INSTALL_REFERRER f - 32

Check to see if it is in the stopped state

1. Enter the Settings - Application management - details page of an application. If the force stop button is not available, the program has been stopped.
2. Enter the device terminal and view the system file cat /data/system/ ES125en-ES126en.xml

Question and answer session

Q: If my program has no activity and only one receiver, how can I activate it to receive the normal broadcast intent

Answer: In fact, if this is the case, the application is not stopped after installation, because it does not have any behavior that users can click directly to remove it from the stopped state. You can receive broadcast intent normally, unless you artificially force it to stop.

Q: Will the system program stop after installation?

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

Question: The promotion broadcast of Google Play is said to be sent after the installation of the program. Is it affected after 3.1

Not affected. The Google document says that INSTALL_REFERRER will be sent after the program is installed. According to the actual log view, INSTALL_REFERRER will be sent after 3.1, when the program is first opened after installation.


Related articles: