Android framework layer Learning Guide

Source: Internet
Author: User
From: http://www.android123.com.cn/androidkaifa/918.html

Many Android Developers may think that learning only about the Java layer is not enough. Here, android123 uses the source code to help you understand the android framework layer.

First, the android Development Network prompts you to learn about the pre-knowledge. First, you must have a C ++ base. If you only need C, you may need c ++ STL standard library, as well as understanding templates and generics will be much harder. At the same time, we must have the idea of OOP. Otherwise, we may not be able to organize large projects like android well, you can use the H file to draw a UML diagram to quickly understand the entire structure.

1. First download the framework layer source code from the android git source code hosting site.

2. for Android, Google uses C ++ internally, which is similar to STL, because some of them only use encapsulation again. We recommend that you directly check the files in utils under the include directory in the base, for example, string8.h, string16.h, and vector. h. keyedvector. H and typehelpers. h

Here, string8 and string16 provide more auxiliary methods than the strings in STL, and are more complete than the standard library, some of them are similar to uint8_t, uint_16t, and uint32_t. Here we can understand the char, short, and INT types in VC, which are 8-bit, 16-bit, and 32-bit integer types, mainly because the marked range is different, using smaller units can save more memory overhead, which is very important for the system. The functions of vector and STL are the same, keyedvector can be treated as a map in STL. It is a hash ing type. The following android123 emphasizes the typehelpers file, which encapsulates the SP template and WP template, many source codes have similar
The definition of static sp <camera> requires a deep understanding of the android sp. If you really want C ++ to be a pediatrics, such

Template <typename T> class sp;
Template <typename T> struct trait_trivial_move <sp <t> {
Enum {value = true };
};

// WP <> can be trivially moved
Template <typename T> class WP;
Template <typename T> struct trait_trivial_move <WP <t> {
Enum {value = true };
};

3. Of course, we recommend that you master the basic C ++ design mode. For example, the single-piece mode can be written in the singleton. h file in C ++,


Template <typename type>
Class Singleton
{
Public:
Static type & getinstance (){
Mutex: autolock _ L (slock );
Type * instance = sinstance;
If (instance = 0 ){
Instance = new type ();
Sinstance = instance;
}
Return * instance;
}

Protected:
~ Singleton (){};
Singleton (){};

PRIVATE:
Singleton (const Singleton &);
Singleton & operator = (const Singleton &);
Static mutex slock;
Static type * sinstance;
};

4. After reading all the structured H files, you can switch to the libs directory of the base. Here the corresponding CPP file contains the specific implementation.

5. The Android framework allows us to better understand the underlying system and develop more competitive products.

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.