I agree with this statement that the Android Framework is just the encapsulation of the underlying system. To understand it thoroughly, you must be familiar with JNI, read C++, understand Java virtual machine, Linux system, even assembly, instruction set, etc. However, that doesn’t mean you need to be familiar with these things to understand the Android Framework! The converse proposition is not equivalent to the original proposition. By the time you’ve learned all of the above, Android will probably be dead (although if you do, it won’t matter what the next operating system is).
For example, think back to when you were learning to speak as a child. Did you learn grammar first? I’m sure that no language education in the world does this. They teach you to call mommy and Daddy first, then some simple words, then some simple sentences, and then you learn grammar when you’re good at it. Same thing. For a person with certain language knowledge, the same is true. When you learn English, you also learn how are you, I am fine, thank you first, right?
If an area is new to you, you have to go ahead and learn more about it through your metacognitive abilities. So, I think don’t wait to do something when everything is ready. Once you decide to do it, go at dawn.
Besides, I don’t think books about source code are that bad; In order to understand the architecture and design of a system, and the problems encountered and choices made at that time, I am afraid that only the system designer can explain clearly; As far as I know, only C++ design and evolution is a “good book” in this sense. People who write blogs, as evangelists, probably don’t understand some of the design — many of the choices are situational and historical; But that doesn’t stop them from teaching you about it. When reading books like Deep Understanding of XXX, I have two experiences:
1. Don’t remember those so-called API call chains, where called, where jumped to where; It doesn’t work, and you can’t remember. What you have to think about and care about is, how does the author track calls? With a function body of thousands of lines, how does the author know where the next key entry is? For example, how to find the correct C++ implementation from Java native functions? A Binder Client call, how does it know where its Server is? Then you can try to track it yourself and see if you lose it; If you can do that, you can almost analyze the source code yourself.
2. Since you can’t remember details, you need to understand, you need to think; Think about why you’re doing it here, whether it’s elegant or unelegant, and if it were you, what would you do? Of course, not everywhere needs to be like this, so I’ll skip the tasteless code. Treat it as a reference book; After their understanding again, again encounter this kind of problem, directly turn over the book, do not follow their own waste of time.
To summarize, if you read a book or blog about source code, don’t worry too much about the complex function call chain unless you want to understand the details. It’s important to learn how to trace and understand the cleanup process. The Android source tree is so large that if you want to read it line by line, you can’t; Even if you did, it wouldn’t work very well — you couldn’t see the wood for the trees. For a simple example, you don’t have to worry about the Activity startup process in AMS or ActivityStack or its SuperXX. Here’s what you need to know: In the Context, Binder calls are made to the system_server process through the AMS Client ActivityManagerNative, and the AMS loop (dealing with the Activity stack and the lifecycle), The Binder calls IApplicationThread back to the Binder thread pool of the App process, sends a Message to the main thread of the App through the Handler, and finally loads the Activity class through the ClassLoader to create the object. Callback corresponding to the lifecycle, the whole process ends.
As someone who’s been there, I agree with @Van Bruce that Android’s capabilities lie outside of Android; As a beginner, I also believe that understanding the Android Framework is not as difficult as you might think.
1. Let’s answer the question head-on. Unlike other books, such as literature, technical books do not have to read every chapter. You must break this habit. In the first place, not all books are worthy of every chapter, every verse, every paragraph, and every sentence. It is a waste of time to spend time reading those of little value. Moreover, as you go on, you will have to master more knowledge and read more books than you have the energy to read them all. If you don’t know what is important, just ask your senior or ask questions in zhihu.
- It is also not true that “many of them cannot be fully understood and cannot be moved by looking at them.” No one can understand at first sight or learn at first sight. It’s a little bit of understanding, a little bit of exploration, and then a little bit of understanding; It doesn’t matter if you don’t understand it once. Read it several times and you will feel it slowly. I still remember that I did not understand Binder, Luo’s blog, Binder Design and Implementation, and the source code. I have read it completely for more than six times. Practice makes perfect, if you can see the book, their own thinking, the source code inside these scattered things into a string, have their own feeling, then the front is the way.
How to learn the Android Framework? There is only one way: Read the F *cking source code. As for how to “smooth” the transition, I don’t think the learning curve is that steep — isn’t the Android Framework code code? Don’t understand because there is no overall grasp.
Whether you’re reading a book or a blog, your ultimate goal is “learn to read source code”, not “learn source code”. It’s not an easy problem to read source code, and I’ve learned a few things:
1. Read more if you don’t understand. As it has been said, no one learns quickly; Especially for beginners, you just read the system source, certainly confused; All things are difficult at the beginning, when you feel difficult and obscure, you will be back to the text; The Android Framework is written in a certain way. If you memorize one text and then read another, you’ll probably know what you’re going to talk about halfway through, even if you don’t understand it either. After memorizing, you can think of the meaning of each sentence; And the above “paragraph”, “sentence” is not ordinary code? In this way, step by step in series, every little makes a mica, and it will come naturally. This is what we say when we read a book a hundred times. If you really want to learn the Framework, read a lot, stick to it, and don’t give up, otherwise it’s bullshit.
2. Read less of what isn’t important. It’s easy to know what it is, so how do you know which code isn’t important? There are two meanings: first, it emphasizes the big picture. When you first learn a module, you need to grasp the whole first and then understand the parts. In this scenario, all the details are unimportant. Second, the logic that really doesn’t matter; When you start learning, there’s no way to know which logic is going to be less impactful, so you need to follow books, blogs, and others to lead the way. If you follow their footsteps through the road, then you walk alone, by this time you are sure to get lost, and then you track, try, and get to the end; You know what’s important and what’s not.
3. Read and think. Learning without thought is labor lost; thought without learning is idle. What does it mean to read the source code with questions? Why do we need to do this? Is this implementation elegant or cliche? Is there a better way to do that? If I were to write it, how would I write it? And so on, with thinking, you have your own understanding.
4. Not everything needs thinking. Connected to the article, the Framework code is also written by people, there is essence, natural dregs, there are tasteless food. You don’t have to ask a hundred thousand why’s for every piece of code. There are usually many solutions to a problem, and the designers at the time chose the current implementation for historical reasons and its own understanding of compatibility issues; Not all implementations are good implementations now, so asking these questions is often pointless, so don’t read too much into it. For example, with Android’s IPC mechanism, why Binder? Perhaps some people say that Socket is not secure and efficient enough; Shared memory is inconvenient to use, and so on. But look at the question: Why did Android adopt Binder as an IPC mechanism? – Android development as you know, most of the time there is not so much why.
5. Take notes. The importance of note-taking is that it allows you to write down your own understanding at one stage, and then when you go further and look back at that understanding and think about what went right and what went wrong, it’s quite an interesting process. I think everyone looks at their previous code and feels like Shabbi somewhere. Summarize your learning process so that you can improve your metacognitive skills.
Finally, civilize communication and refuse to quarrel.