Do you know these Framework questions? wait online, hurry up

insert image description here

foreword

I would like to give you an overview of the recent Android interviews, because the Golden Nine and Silver October are approaching, and there are more and more interviews that can be arranged, but many friends also mentioned a question: "Currently Android interviews are basically asked about Framework , making many people miserable."

This situation has also been accumulated over time. Now there are too many programmers, and the company has some choices, but we have no choice. Then the company must need better and stronger employees, and Framework is not only a good detection method, but also Can recruit a group of low-level system development programmers for the company in advance.

When it comes to business, first hang out the questions that my friends sent me recently

What is ActivityManagerService? When is it initialized? What is its function?

ActivityManagerService is mainly responsible for the startup, switching, scheduling of the four major components in the system, and the management and scheduling of application processes. Its responsibilities are similar to the process management and scheduling modules in the operating system. The timing of ActivityManagerService initialization is very clear, that is, when the SystemServer process is started, ActivityManagerService will be initialized.

(system startup process)

If you open an App, you need AMS to notify the zygote process

All Activity life cycle AMS to control

What is ActivityThread? What is ApplicationThread? The difference between them

ActivityThread
in Android represents the main thread of Android. After creating a new process, the main function is loaded, and then executes a loop cycle
to make the current thread enter the message loop, and as the main thread
ApplicationThread
ApplicationThread is the internal class of ActivityThread. A Binder object. Here it is the server side of the IApplicationThread object waiting for the request from the client side and then processing it. The biggest client is AMS.

What is Instrumentation? What is the relationship with ActivityThread?

The interaction between AMS and ActivityThread, such as the creation and suspension of Activity, is actually operated by Instrumentation.

Each Activity holds a reference to an Instrumentation object, and there is only one Instrumentation in the entire process.

The initialization of mInstrumentation can be used to independently control the life cycle of a component in the ActivityThread:: handleBindApplication function.

"startActivity will call 'mInstrumentation.execStartActivity0; mInstrumentation will use AMS for the startActivity method of the Activity, and AMS will notify the Zygote process to fork the child process through socket communication

How is the communication between ActivityManagerService and zygote process realized?

When the application starts, the Launcher process requests AMS.
AMS sends a request to create an application process, and the Zygote process accepts the request and forks the
application process. The client sends the request.
Call the Process.start() method to create a new process.
The connection calls
the ZygoteState.connect()
method
, and ZygoteState is
the internal class of ZygoteProcess.
LocalSocket used in ZygoteState

public static ZygoteState connect( LocalSocketAddress address)
throws IOException {
    
    
DataInputStream zygoteInputStream = null ;
BufferedWriter zygoteWriter =
null;
final LocalSocket zygoteSocket = new LocalSocket( ) ;
try {
    
    
zygoteSocket .connect(address);
zygoteInputStream = new DataInputStream(zygoteSocket .getInputStream()) ;
zygoteWriter =
new BufferedWriter( new OutputStreamWriter(
zygoteSocket .getOutputStream()) , 256) ;
} catch (IOException ex) {
    
    
try {
    
    
zygoteSocket .close() ;
} catch (IOException ignore) {
    
    
}throw ex ;
}
return new ZygoteState(zygoteSocket , zygoteInputStream , zygoteWriter ,
Arrays .asList(abiListString .split(","))) ;
}

Zygote processes the client request and
the Zygote server calls
ZygoteConnection.processOneCommand() to
process the parameters after receiving the parameters

, and the fork process finally finds
and executes the main() method of the ActivityThread class through fifindStaticMain(), and the child process starts

Here are a few selected questions to answer . For more comprehensive analysis of Framework interview questions, you can scan the QR code below

## "Andrio Framework Interview Question Analysis Collection"

●Analysis of system start-up process interview questions

●Analysis of Binder interview questions

●Analysis of Handler interview questions

●AMS interview questions analysis

img

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/Misdirection_XG/article/details/132226196