888 Android advanced interview questions, introduction to Android componentization, sharing a little interview experience

Preface

Many companies face a problem in hiring people;
"Our recruitment requirements are not high, so we can do projects, but why can't we hire people?"

Many companies still face a problem. When recruiting, this person is good in all aspects, but after being hired, he can't work and his performance is mediocre.

To solve the above two problems, we need a standard to measure people's ability. This standard is not only suitable for recruitment, but also for assessment, grade evaluation, etc. I call this standard a skill tree.

The skill tree mentioned here includes not only technical capabilities, but also work capabilities. I always believe that a person's work ability is not equal to his technical ability. In addition to the technology itself, the work ability also includes the person's overall qualities (cooperative communication, work attitude, desire for self-realization, etc.). Many people have good technical abilities, but they are just an executor at work and it is difficult to be a big task.

The skill tree of Android application developers listed below is only my understanding based on my own work experience and feelings. Whether for a team or an individual, it is not necessarily a standard, but it has a certain reference value.

Start mode

To accurately measure the startup time of the APP, we must first understand the entire startup process of the APP. The startup process can generally be divided into the following three categories:

Iqiyi Android client startup optimization and analysis

As can be seen from the above figure, during the startup process, in the Cold mode, the most things are done in the life cycle and the startup time is the longest. Therefore, we use cold startup to measure the APP startup time. During the startup process, how to determine which life cycles affect the startup speed?

Boot process

We know that the startup and operation of APP is the process by which the Linux system creates processes and component objects, and processes component messages in the UI thread.

Startup process diagram:

The app startup process can be divided into three stages:

3.1 Create process

When the app is started, if the current app process does not exist, a new process will be created; after the main app process is started, if a component is started and the component has the android:process attribute set, the process running by the component does not exist, A new process will also be created.

It should be noted that if multiple processes are included in the initialized component during the startup phase, multiple processes will be created, and BindApplication operations will be repeated multiple times

3.2 Create UI thread and Handler

After the process is created, it will execute the ActivityThread entry function through reflection, create a Handler, prepareMainLooper in the current thread, and receive the message of the component in the Handler. Let's take a look at the messages processed in the Handler:

  • LAUNCH_ACTIVITY, start, execute Activity
  • RESUME_ACTIVITY, restore Activity
  • BIND_APPLICATION, start the app
  • BIND_SERVICE, Service creation, onBind
  • LOW_MEMORY, insufficient memory, recycling daemon

In sMainThreadHandler, there are a lot of messages processed. Here is only a list of operations that may be performed during the startup phase. These operations are all running in the Main Thread, which is blocking for startup.

The Activity life cycle naturally needs to be executed during the startup phase. However, for the creation of the Service, Trim_memory callback, broadcast reception and other operations, it is necessary to focus on the time-consuming operations.

3.3 Activity running and drawing

The first two processes, creating process and UI thread and Handler, are all determined by the system. As far as APP developers are concerned, their execution time cannot be controlled. At this stage, the execution of BindApplication and Acitivity life cycle can be determined by Developer customization.

After the Activity executes to onResume, it executes to ViewRootImpl, executes performTraversals twice, and in the second traversal operation, executes the performDraw operation and informs the RenderThread thread to perform drawing.

From the three stages of startup, we can see that the length of startup time is determined by the amount of time consumed in the main thread. Therefore, our optimization work is mainly focused on troubleshooting the time consumed in the main thread. Sexual work and reasonable optimization. On Android phones, system resources are limited. Too many asynchronous threads will preempt the CPU and cause the main thread execution time slice interval to increase. Similarly, memory consumption status and GC frequency will also affect the startup time

At last

This article has been included in the open source project GitHub , which contains self-learning programming routes in different directions, interview question collections/face sutras, and a series of technical articles, etc. The resources are continuously updated...

Part of the information that has been updated so far, if you need to take it yourself:



.(img-8K0LwyOS-1611133204605)]
[External link image is being transferred...(img-oRzeP65i-1611133204607)]

Guess you like

Origin blog.csdn.net/fjfdhduuffududu/article/details/112897355