14.01.2013 Views

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3: Creating <strong>Application</strong>s and Activities<br />

necessary, to free resources for higher-priority applications — generally those that are interacting<br />

directly with the user at the time. The prioritization process is discussed in the next section.<br />

Understanding <strong>Application</strong> Priority<br />

and Process States<br />

The order in which processes are killed to reclaim resources is determined by the priority of the hosted<br />

applications. An application’s priority is equal to its highest-priority component.<br />

Where two applications have the same priority, the process that has been at a lower priority longest<br />

will be killed fi rst. Process priority is also affected by interprocess dependencies; if an application has a<br />

dependency on a Service or Content Provider supplied by a second application, the secondary application<br />

will have at least as high a priority as the application it supports.<br />

All Android applications will remain running and in memory until the system needs its resources for<br />

other applications.<br />

Figure 3-3 shows the priority tree used to determine the order of application termination.<br />

1. Active Process<br />

2. Visible Process<br />

3. Started Service Process<br />

4. Background Process<br />

Figure 3-3<br />

5. Empty Process<br />

Critical Priority<br />

High Priority<br />

Low Priority<br />

It’s important to structure your application correctly to ensure that its priority is appropriate for the<br />

work it’s doing. If you don’t, your application could be killed while it’s in the middle of something<br />

important.<br />

The following list details each of the application states shown in Figure 3-3, explaining how the state is<br />

determined by the application components comprising it:<br />

Active Processes<br />

❑ Active (foreground) processes are those hosting applications with components<br />

currently interacting with the user. These are the processes Android is trying to keep<br />

responsive by reclaiming resources. There are generally very few of these processes, and they<br />

will be killed only as a last resort.<br />

51

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!