An analysis of how Android improves service priority _android

Source: Internet
Author: User

The examples in this article describe how Android improves service priority. Share to everyone for your reference, specific as follows:

The Android system has its own set of methods for memory management, in order to ensure the orderly and stable delivery of the system, the system will be automatically allocated, the control program memory use. When the system feels the current resources are very limited, in order to ensure that some high priority programs can run, it will kill some of the programs or services he does not think important to free memory. This ensures that programs that are really useful to users are still running. If your Service meets this situation, you'll probably get killed first. But if you increase the service priority so that he can stay a little while, we can use Setforeground (true) to set the service priority.

Why the foreground? The service that is started by default is marked as background, and the currently running activity is typically marked as foreground, which means that you set up a foreground for the service so that he has the same priority as the running activity. A certain improvement. When this doesn't guarantee that your Service will never be killed, it just increases his priority.

Starting with Android 1.5, a service that has been started can call Startforeground (int, Notification) to place the service in a foreground state, calling Stopforeground ( Boolean) to place the service in the background state.

We will call Startforeground (int, Notification) to pass in the parameter Notification, which will display the foreground service in progress in the status bar. The background service is not displayed in the status bar.

In Android 1.0, put a service in the foreground state:

Setforeground (true);
Mnm.notify (ID, notification);

To place a service in the background state:

Mnm.cancel (ID);
Setforeground (FALSE);

By contrast, calling Setforeground (Boolean) in the 1.0 API simply changes the state of the service, and the user is not aware of it. The new API enforces notification and changes to the service state, and the foreground service is displayed in the status bar, and the background service does not.

Remote Service Controller & Binding

Call service across processes. Do not study for the time being.

For more information on Android-related content readers can view the site topics: "Android Database Operating skills summary", "Android programming activity Operation Skills Summary", "Android File Operation skills Summary", " Android programming development of the SD card operation method Summary, "Android Development introduction and Advanced Course", "Android Resource Operation skills Summary", "Android View tips Summary" and "Android Control usage Summary"

I hope this article will help you with the Android program.

Related Article

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.