随笔分类 -  Android源码学习

主要是对android 4.0源码的学习笔记的记录
摘要: 模板方法模式定义:defines the skeleton of an algorithm in a method, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.定义一个方法操作算法的框架(骨架结构),而将一些步骤延迟到子类中。 阅读全文
posted @ 2013-01-20 16:45 叶梅树 阅读(5015) 评论(3) 推荐(1) 编辑
摘要:工厂方法模式定义:Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.定义一个用于创建对象的接口,让子类决定实例化哪一个类。工厂方法使一个类的实例化延迟到其子类。常用的工厂方法模式结构:如上图所示 阅读全文
posted @ 2013-01-08 10:03 叶梅树 阅读(2719) 评论(4) 推荐(1) 编辑
摘要:适配器模式定义:Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatile interfaces.将一个类的接口变成客户端所期待的另一中接口,从而使原本因接口不匹配而无法在一起工作的两个类能够在一起工作。其中用到适配器模式的经典例子就是 阅读全文
posted @ 2013-01-06 22:52 叶梅树 阅读(5155) 评论(4) 推荐(3) 编辑
摘要:组合模式定义:Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.将对象组合成树形结构以表示“部分-整体”的层次结构,使得用户对单个对象和组合对象的使用具有一致性。 如上图所示 阅读全文
posted @ 2013-01-06 10:11 叶梅树 阅读(2791) 评论(0) 推荐(0) 编辑
摘要:观察者模式定义:Define a one-to-many dependency between objects so that when one object changes state, all its dependents aer notified and updated automatically.定义对象间一种一对多的依赖关系,使得当一个对象改变状态,则所有依赖于它的对象都会得到通知并被自动更新。 如上图所示 阅读全文
posted @ 2013-01-05 12:11 叶梅树 阅读(1829) 评论(0) 推荐(0) 编辑
摘要:单例模式定义:Ensure a class has only one instance, and provide a global point of access to it.动态确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例。 如上图所示(截取自《Head First Design Patterns》一书)。通过使用private的构造函数确保了在一个应用中产生一个实例,并且是自行实例化(在Singleton中自己使用new Singleton())。二、单例模式优势由于单例模式在内存 阅读全文
posted @ 2013-01-04 10:08 叶梅树 阅读(8187) 评论(4) 推荐(0) 编辑
摘要:装饰模式定义:Attach additional responsibilities to an object dynamically keeping the same interface. Decoators provide a flexible alternative to subclassing for extending functionality.动态地给一个对象添加一些额外的职责。就增加功能来说,装饰模式相比生成子类更为灵活。 如上图所示(截取自《Head First Design Patterns 阅读全文
posted @ 2012-12-30 00:49 叶梅树 阅读(4626) 评论(7) 推荐(3) 编辑
摘要:通过Android源码学习之浅析SystemServer脉络知道了SystemServer是怎么通过利用JNI,但相继的问题出现了:SystemServer是干嘛用的?本人从《深入理解Android 卷2》截取摘录这一问题的回答: SystemServer是什么?它是Android Java的两大支柱之一。另外一个支柱是专门负责孵化Java进程的Zygote。这两大支柱倒了一个,都会导致Android Java的崩溃(所有由Zygote孵化的Java进程都会被销毁,而SystemServer就是由Zygote孵化而来)。若Android Java真的崩溃了,则Linux系统中的进程init会 阅读全文
posted @ 2012-12-26 18:37 叶梅树 阅读(6309) 评论(0) 推荐(1) 编辑
摘要:在之前的博文中《Android源码学习之如何创建使用JNI》和《Android源码学习之如何使用eclipse+NDK》中,浅谈了如何创建使用JNI和如何利用NDK工具开发创建和lib**.so(Windows下)库和调用Naive函数,做了这些工作只有一个目的,就是因为Android源码中“大量”的使用到Native,所以了解一些Native语言和Java如何与Native互通,对分析Android源码还是有很大的帮助的(好像废话很多~~~)。本人通过对SystemServer源码进行浅析,看它是如何设计的。 首先利用Source Insight工具搜索到SystemServer.java. 阅读全文
posted @ 2012-12-26 09:30 叶梅树 阅读(5060) 评论(0) 推荐(1) 编辑
摘要:网上已经有太多的有关如何配置eclipse+NDK了,本人就不再重复这些了,只是想记录下自己开始写第一个NDK程序的整个流程(保证可执行),共自己和大家分享。首先安装一个能够支持Native代码的eclipse插件Sequoyah,然后在eclipse中的“窗口-首选项-Android”中多出来了一个“本机开发”选项,在“NDK Location”选择你的android-ndk的路径。有了Sequoyah插件进行Android Native开发就简单多了。下面根据自己的第一个Android Native程序开发过程,做一个记录。1. 创建Android应用程序MyFirstNativeStor 阅读全文
posted @ 2012-12-24 11:00 叶梅树 阅读(5685) 评论(8) 推荐(2) 编辑
摘要:在Android平台下,JNI就是一座Java世界和Native世界之间的桥梁。因此要学好Android的源码,首先就要懂得什么是JNI,如何使用JNI。 JNI是Java Native Interface的缩写。从Java 1.1开始,Java Native Interface (JNI)标准成为java平台的一部分,它允许Java代码和其他语言写的代码进行交互。JNI一开始是为了本地已编译语言,尤其是C和C++而设计的,但是它并不妨碍你使用其他语言,只要调用约定受支持就可以了。使用java与本地已编译的代码交互,通常会丧失平台可移植性。但是,有些情况下这样做是可以接受的,甚至是必... 阅读全文
posted @ 2012-11-30 18:24 叶梅树 阅读(2161) 评论(0) 推荐(0) 编辑