How do programmers technically paddle, organize several important Android knowledge, the full version is open for download

career plan

Android系统的市场地位
Android程序开发的技能成长经验
Android程序员为什么需要学习Html5
Android软件工程师为什么不会被前端替代
为什么小程序无法替代原生开发
为什么Html5无法取代NativeAPP
Html5在Android中的应用场景
如何成为一名合格的高级Android程序员

The interviewer asked a question, let’s take a look at the performance of the three students A, B and C

A

Interviewer: Talk about the role of Application.

A : Application is a system component that will be created after the application process is created, so it can be used to do some initialization operations; Application life cycle is as long as the application process, so it can be used to provide Context to the class library; because all Context can be obtained Application can be used to save and transfer global variables.

Interviewer : Do you usually put global variables in Application? What if the application is recycled in the background and the value is lost when reopened?

A : Yes, it's very convenient, just do a fault tolerance

Interviewer : Okay, go back and wait for the notice


B

Interviewer : talk about the understanding of Application

B : Role: do initialization and provide context. In addition, Application is a Context, which directly inherits ContextWrapper; the member variable mBase of this ContextWrapper can be used to store the ContextImpl implemented by the system, so that when we call the Context method of Application, we will finally call the method of ContextImpl through a static proxy. . We call the getBaseContext method of ContextWrapper to get an instance of ContextImpl

Interviewer : Do you usually put global variables in Application? What if the application is recycled in the background and the value is lost when reopened?

B : No, save global variables with static variables, or singletons can gather them in a more suitable location.
To avoid data loss when the application is recycled, when you can pass parameters on the page, pass the parameters through the Intent, so that it is worthwhile to open and retrieve the parameters from the Intent after being recycled. If the amount of data is large, you can also consider data persistence; another method is to save the corresponding data when it is recycled and restore the data when it is reopened through onSaveInstanceState and onRestoreInstanceState.

Interviewer : Tell me about the life cycle of Application

B : Compared with Activity, the life cycle of Application is not too simple. The constructor is called when it is first created, and then the system is ready to inject the ContextImpl into the Application through the attachBaseContext( Context) method, and then call the onCreate method we are most familiar with. There is also an onTerminate method in the API that will call back when the process is killed, but it only takes effect in the simulator, so you don't need to pay attention.

Interviewer : Can you talk about the initialization process of Application?

B : Basically those mentioned above, I didn’t understand it in detail

Interviewer : Okay, go back and wait for the notice


C

Interviewer : Talk about the initialization process of Application

C : Application is initialized after the application process is created:

ActivityThread calls the attachApplication method of the Binder object (IActivityManager) of
AMS. After receiving the request, AMS calls the bindApplication method of
ActivityThread. ActivityThread This side receives the request and then assembles an AppBindData object, encapsulates all parameters, and sends it to the main thread for execution through the handler

The main thread loops to this message and calls handleBindApplication to actually process the initialization Application

When handleBindApplication talked about "Context", the initialization of Activity was similar. Recap:

ClassLoader loads the Application class, instantiates
the ContextImpl used to initialize the Applicaction
through the Application.attach( Context) method, calls attachBaseContext( Context) to inject the ContextImpl into the Application and
finally calls Application.OnCreate()

Then Application is initialized

Interviewer : Why doesn’t the process creation complete directly call handleBindApplication to create the Application, and then go to AMS to make a circle

C : The attachApplication of AMS is called not only to create the Application, but also the four major components of the application may be called before the process is created but cannot be started; now that the process is created, the application has to be created to process these components to be started. Therefore, unified scheduling is required through AMS. If the application creation and onCreate callback takes time, it will also affect the startup time of these components to be started

Interviewer : Yes, let's talk about other things.

At last

It is said that the Internet is cold. In fact, it is nothing more than you got on the wrong car and you wear less (skills). If you get on the right car and your own technical ability is strong enough, the cost of replacing the company is high. How could you be laid off? It's just to eliminate the end business Curd! Nowadays, there is a flood of junior programmers in the market. This set of tutorials is aimed at Android development engineers who are 1-6 years old. They are in a bottleneck period. Those who want to break through their salary increases in the next year, advanced Android intermediate and senior, architects are even more important to you. Like a fish in water, get it quickly!

Click on the above [HD Technical Mind Map] and [Supporting Architecture Technology PDF]: Android architecture video + BAT interview topic PDF + study notes , or private message reply [Skills Upgrading] to get it!

Why some people will always be better than you is because they are very good and have been working hard to become better, and are you still satisfied with the status quo and chuckle in your heart!

The road of Android architects is very long, let's encourage together!

Guess you like

Origin blog.csdn.net/dajie1213/article/details/112987184