Description of the Android apk format

Source: Internet
Author: User

The structure of Android apk is really amazing. It absorbs the idea of client/service. apk does not have its own independent entry function, but only contains one or more component, when executing the program, determine the required component based on the manifest configuration file.

Conponent activation is triggered by intent. intent stands for an action that includes operation and operation data, which is equivalent to the component being a service provider. intent brings requests, then it executes the request. In addition, intent can specify component to execute the request, or select the most appropriate component based on filter matching without specifying component to complete the request.

In addition, the process at the application layer is distinguished by the linux user ID. Each process corresponds to a virtual machine, but one process can run multiple applications, it is not limited to one. As a matter of fact, an application is composed of multiple components. Multiple applications can be seen as an apk composed of many components.

Let's take a look at the four most basic component types:

1. activity
In Android apk, activity is a UI concept. An application can have multiple activities. In fact, an Activity is a window, and its content is various views. Use setContentView () to associate the window with the content.

2. service
The service can actually be seen as a component running in the background without the UI. In Android, this service is divided into two types, one is that the service is required to run in a local process, that is to say, the program runs in a process with the application, and the other is that the service runs in other processes.

3. Broadcast receivers
This is actually an intent receiver. When the system broadcasts an intent, it receives events of interest to the application, and broadcast receivers does not have a UI. The apk can directly contain this component or register one at runtime.

4. Android apk
In terms of translation, this provides a public interface for applications to share their data. Other applications can access the data based on these public interfaces. It provides an adaptation port content resolver through which the application operates the content provider. When the application starts to execute, it first reads manifest, initializes some component based on the xml configuration file, and then it stops waiting for the arrival of intent.

Therefore, several important concepts in an application are component, manifest. xml, intent, and intent-filter. In component, activity and service are important. Next let's take a look at the life cycle of a process: after a process is opened, the operating system will try its best to maintain its running status, when the memory is insufficient, the system will force the kill process according to the following priority:

1. The empty process is first considered to be shut down by a process that does not contain any activated component. The main reason for retaining such a process is that it can be faster during restart, therefore, when the memory is insufficient, such processes should be killed first.

2. background process
The second reason is that the thread with activiry is closed, but the activity is invisible.

3. visible process
The third consideration is that the activity of the process is visible, but it is not the one where forground is interacting with the user.

4. forground
The last thing to consider is the process where activiry is at the very beginning. There is another problem here, that is, if a process is bound with a service, its priority is higher than that of a background running process, in other words, it is not so easy to kill.

  • Google gave up "Do not do evil "? Desire to monopolize Android
  • How Android applications are built
  • Analysis on Android DDMS Performance
  • Explore how Android DDMS works
  • Android source code operation tips

Therefore, it is much safer to bind a service when designing an application than to open a thread in the process to run a long time task. In manifest. xml, each component has a process option to specify the processes it runs so that the Android apkt of an application can run in a process.

You can also run the component of multiple applications in one process to share data. In java, the technical expert provides an IDL Language to automatically generate the source code for remote process calls. The application only needs to implement some of its interfaces, which facilitates RPC programming.

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.