IMPortant
The emulator should be prefered to genymotion!!!
www.genymotion.com

Chapter1~2
1.Android SDK selection
keyword: android device dashboard
url : http://developer.android.com/about/dashboards/index.html
snapshot from front-2014: 

2. Android Stack overview

3. Native Libraries(图中的Libraries)
The native libraries are C/C++ libraries.
(1) WebKit: Safari, Chrome都在用的web-rendering engine
(2) SQLite: A full-featured SQL database
(3) Apache Harmony : An open source implementation of Java
(4) OpenGL : 3D Graphics libraries
(5) OpenSSL : the secure locket layer
(6) Bionic : 这是Standard C library的重写,出于Technology与License两方面考虑

4. Dalvik (图中的Runtime)
Dalvik is VM designed specifically fro Android.

====================================================================
Chapter 3 Quick Start

1. 关于/与\ 还有~
/ 斜杠 ,  Mac, Linux
\ 反斜杠, windows

~的路径:
mac: /Users/xugg
linux: /home/xugg
win7: C:\Users\xugg
winxp: C:\Documents and settings\xugg

2. Installing the Android SDK
(1) Downloading ADT(Adnroid developor tools) : http://developer.android.com/sdk/index.html?utm_source=weibolife
(2) 选择安装c:\apps\android-sdk (实际是copy sdk下的文件到此)
(3) 配置,因为工具可能会直接在命令行中执行
     ~/android-sdk/tools/
     ~/android-sdk/platform-tools/
     回到系统PATH
(4) IDE (Integrated Development Environment) Eclipse : https://www.eclipse.org/ 下载java版,而不是EE版
     d/e:\workspace
(5) 设置 , 新的adt下直接有eclipse可运行。。。若不管,要独立eclipse也行,则:
     Help -> Install New Software
     ADT - https://dl-ssl.google.com/android/eclipse  选择android DDMS, android Development Tools
     上面若有问题,改https为http
注:java环境更应优先

3. Hello world
(1) File -> new -> android project , 第一次没有,用File-> new -> other -> Android Application Project
(2) Application Name是在app store之类上看的,写Hello, World!!!
     Project Name用双大写,HelloWorld
     Package Name 是domain的逆,如com.example.calculator是example.com下的一个caculator
     用选择com.mazei.helloworld
     sdk选择有:
          min最小 8
          target sdk 18
          complie sdk  19
     这就有疑问了,target到底有啥讲究?
     acitivty: 这是为了适应不同屏幕尺寸的,用HelloWorld
(3) Manifest File
AndroidManifest.xml 这个文件是。。。出货单
(4) Layout XML code
res/layout/main.xml
实际项目中为res/layout/activity_hello_word.xml
(5) Strings
所有文字
res/values/strings.xml
(6) The R File
连接Java与资源
gen 下有R.java
(7) Java Source code
(8) The Emulator
Android Virtual Device (AVD)
创建一个AVD, 前一个sdk管理

存在bug,直接 run有问题,需要先运行vm,然后再手动选择运行

====================================================================
Chapter 4 Main Building Blocks

1. What are Main Building Blocks
拆分成理论上的独立单元,又可放在一起成为完整的包
2. Activities
通常是一个屏幕, 就像网站的Page
3. Activity Life Cycle
载入一个Activity是相当expensive的
要开一个Linux process, 分配内存给UI对象,载入所有的Layout
所以有个Activity Manager来管理activity生命周期

starting state: 没有进程在,一旦有了就是running, 这一过程最expensive,耗电
runnig state: 只有一个,给够资源
paused state : 屏幕显示的,但没有交互
stopped state : not visible, but still in memory
destroyed state : no longer in memory,,  这时的操作是没保证的,因为可能已经destroy了,所以推荐在paused状态做

4. Intents
Intents are like events or messages. You can use them to start activities, start/stop services, or send broadcasts.
会触发一个activity
异步的
可以是清楚的或不清楚的,explicit or implicit, 清楚的指明接收的component, 不清楚的只指出接收者的类型

5. Services
后台运行,与用户无交互,可执行与activity一样的功能,当然除了交互。例如后台音乐。
通常的,Services与Activities在一个main application thread上运行,而不是另开线程。


6. Content Providers
Content Providers are interfaces for sharing data between applications.
小数据可以通过itents传,更好的方案是content providers

7. Broadcast Receivers
implementation of publish/subscribe mechanism, or more precisely, an Observer pattern.
Receiver是个静止代码,当它订阅的事件发生时激活一次。如有电话来,有SMS,没电了等,所有订阅的都收到
Receiver本身无界面,无占内存运行,一旦triggered,可能会开启activitiy, service or something else.

8. Application Context
上下文嘛
第一个component开启时,Context创建,
application alive,则context存在, 与activities life cycle 无关
得到context命令:Context.getApplicationContext() 或 Activity.getApplication()
activities ,  services 是context的子类

====================================================================
Chapter 5 Yamba Proejct Overview

a twitter-like application
Yamba = Yet Another Micro Blogging App
https://github.com/twitter-university/yamba
https://github.com/twitter-university/LearningAndroidYamba

1. Design of the entire Yamba

Part1 : Android User Interface (chapter 6)
developing first component of the Yamba : the Status Update screen.
涉及:activity, networking, multithreading, debugging
Layouts, views, UI, 

Part2 : Preferences, Filesystem, Options, Menu, and Intents (chapter 7)
涉及: activity, menu system, intents, filesystem

Part3 : Android Services (Chapter8)
backgroup services

Part4: Working with Databases (Chapter 9)
SQLite

Part5 : Lists and Adapters (Chapter 10)

Part6 : Broadcast Receivers (Chapter11)

Part7: Content Providers(Chapter12)

Part8 : System Services (Chapter13)


====================================================================
Chapter 6. Android User Interface

做界面有两办法:declarative, programmatic
delcarative: 写xml啊,就像写html. 优势是可以用what-you-see-is-what-you-get tools. 缺点是不很好的支持用户输入
programmatic: 写java代码来做UI.与Java AWT, Java Swing很像,如按钮,创建按钮对象,加入容器,各种属性定义,加点击事件
一般的做法是:declarative来定义所有static的,如屏幕,widgets等,然后用programmatic来定义用户运作

(1) LinearLayout
simplest and most common,但一般不是最好选择
重要属性layout_orientation=vertical|horizontal
多个线性最好不要nested, 而选用Relative Layout, 因为更多的cpu, battery

(2) TableLayout
只由TableRow组成, 有tb tr td
重要属性:stretch_columns, *表示所有列均可stretch

(3) FrameLayout
叠纸牌一样,最后一张在最上面

(4) Relative Layout
要设置ID, 高效

(5) Absolute Layout
所见即所得最喜欢用,不够flexable, 不同分辨率是问题

I. 开工写或画XML UI:
1) res/layout/main.xml?  
     实践中,main.xml没有,而是根据我确定的activity的名字生成了activity_status.xml  (StatusActivity)
     一致性考虑改名为status.xml来匹配StatusActivity? 我相信不用改也行,实践就改下吧
     改了后,在StatusActivity下的onCreate中也会自动改为setContentView(R.layout.status);
2) four componet
     一个最上面,用TextView
     中间显示140 character, 用EditText
     下面用Button
     一个layout来contain所有widgets
3)important widget properties
layout_height, layout_width: fill_parent(占父空间), wrap_content(按需占用)
layout_weight: 是个[0-1]的数,默认重量为0, 越接近1越最后满足
layout_gravity: 可以设置为top,center, left等。 width是fill_parent的没啥作用,但若是wrap_content,则有用了。这与gravity不一样
text: 多语言考虑设置到strings.xml中,用时@string/titleStatus
id: 能不用就不要用,Java代码调用的要设置,有格式@+id/someName,一般会类型取名,如@+id/buttonUpdate

4) String Resource
取名加了类型如title, hint, button。如titleYamba, buttonUpdate

II. 接着写Java UI:
原则是尽可能的xml后再java
不论是写Activities, services, broadcast receivers, 还是content providers都是inherit base class , 产生subclass, 如Activity的子类override onCreate()方法
onCreate: 第一次创建时,从starting 到running, 参数是bundle,是小量的数据,通过intent传递给activity, 参数只支持base type的数据,复杂的要encode
这样一种创建好父类,等待各种子类去添加空白处,是Template pattern
Override一个方法时,要执行父类的方法,如super.onCreate()
从xml文件变成java 内存 中的对象,称为inflating from xml , inflate, 代码是:setContentView(R.layout.status); 

1)添加Jar
拖到项目中,选择copy;project->properties->java build path -> libraries -> add jars

2) Updateing the manifest file for internet permission
AndroidManifest.xml
< uses-permission android:name ="android.permission.INTERNET" />

3)Logging in Android
Log.d(TAG, "onClicked");
Tag: app, class , module名,一般情况下, 一个好的习惯是定义TAG作为Java constant for your entire class such as:
private static final String TAG = "StatusActivity";
日志有severity levels:
.d(): debug level
.w() : warning
.i() : info
.wtf() : errors that should never happen(It stands for What a Terrible Failure, in case you were wondering)

4) eclipse 添加library的小tips
Source -> Organize Imports,  或 CTRL + O, 注意是Apache的Log与 Android的Log

5) LogCat
The Android system log is outputted to LogCat, a standarized system-wide logging mechanism.
两个方法查看:Eclipse DDMS perspective或Command line
DDMS stands for Dalvik Debug Monitor Server. 用于连接设备上运行的程序与开发环境如Eclipse

也可以命令行:
adb logcat
adb logcat StatusActivity:* *:S        :这个表示只看Tag为StatusActivity, S=Slience, 一直开着有好处,可以速度发现问题

这个不对:adb logcat -d -i -w -e -f    intends debug, information, warning, error, fatal

adb logcat StatusActivity:* *:S
V - Verbose (lowest priority)
D - Debug
I - Info
E - Error
F - Fatal
S - Silent

出现致命错误:02-20 04:04:12.565: E/AndroidRuntime(1141): java.lang.NoClassDefFoundError: winterwell.jtwitter.Twitter ,,就是jar中的类不认识 
上图解决该问题
stackoverflow reference: http://stackoverflow.com/questions/8678630/noclassdeffounderror-for-code-in-an-java-library-on-android


02-20 04:19:01.165: E/AndroidRuntime(1296): android.os.NetworkOnMainThreadException  新错误出现,这个错误正是下一个话题
6)Threading in Android
定义Thread: A thread is a sequence of instructions executed in order.
Single Thread: 所有命令连续执行,排队。blocking. 例如UI thread
现在来解释上面的错误,NetworkOnMainThreadException. MainThread就表示是Single Thread, 而Network不稳定,可能1秒,也可能一天,要MainThread等一天吗?
(实际上,Android默认5秒没反应kill activity)

7) Multithreaded execution
目的:main thread running foreground and the additional threads as running in the background.
实现的方法: Java Thread class
     用标准Java 的thread有问题,因为main thread不会让其他thread来更新main UI thread上的组件
     所以Android有改进, AsyncTask

8)AsyncTask
AsyncTask is an Android mechanism created to help handle long operations that need to report to UI thread.
具体实现,创建AsyncTask的子类,实现doInBackground(), onProgressUpdate(), onPostExecute()等方法。
class PostToTwitter extends AsyncTask<String, Integer, String>{
doInBackground(): protected String doInBackground(String... statuses) {
     String... indicate that this is an anrray of Strings 注意到String对应类的范化的String(1)
doProgressUpdate(): is called whenever there's progress in the task execution. The progress reported from the doInBackground(). 
          protected void onProgressUpdate(Integer... values) {  注意到Integer对应类的范化的Integer(2)
onPostExecute(): is called when our task completes.
          protected void onPostExecute(String result) {
          这里的result就是doInBackground的return, 这里是String, 注意到String对应类的范化的String(3)

一个AsyncTask的使用,实例化后直接执行execute(), 给的参数会给到doInBackground(), String会自动转为String...
      String status = editText.getText().toString();
       new PostToTwitter().execute(status);
9) Toast
Toast is a feature of the Android UI which is to display a quick message on the screen.
Toast uses the maktext() static method to make the actual mesage.
最扣要show()一下。

10) 错误02-21 04:23:13.067: E/AndroidRuntime(1088): Caused by: libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)
02-24 00:52:50.889: E/AndroidRuntime(1065): Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
Since permissions are shown to the user during installation.
一直找不到原因,aapb.exe经常性爆,决断 应该是xml文件有问题,重新一点点写,写一点跑一下运行,最终重新写的没有问题

11) DDMS: Dalvik Debug Monitor Server, DDMS is the connection between your application running on the device and your development environment, such as Eclipse
DDMS perspective才可以logcat

12)Adding Color and Graphics
12-1) 加图:
难看,加图片背景:归为drawable
/res/drawable-hdpi  : for devices with high-density screens(density 密度)
/res/drawable-mdpi : medium-density
/res/drawable-ldpi: low-density
图片优先png,而非gif 因为lossless and doesn't require any patent licenses.
R.drawable.background

在画图界面选择时,可以打开outline更方便:Window->Show View->Outline

12-2)加色彩
ARGB : A表示transparency,透明度, a is optional, 0~255, 十六进制0~FF,实际应用为AARRGGBB, 每位值为0~F,可简写为ARGB, 如#3A9F = #33AA99FF, #表示16进制啊,hexadecimal。
选择将editText背景色改为#cfff : 是一种透明的白
标题字的颜色改为白色, textColor=#fff, 也可以@android:color/white


13) 其他资源
13-1) 横向资源:/red/layou-land/status.xml  rotate portrait  landscape
多语言: res/values-fr-rCA/strings.xml   a French-speaking part of Canada。 -fr 指法语  -rCa region is Canada。 在加拿大设置了法语就会用这个,找不到用默认
记不住名字?可以用File->new ->Android XML File

14) Optimizing the user interface
The user interface is one of the most expensive parts of a typical Android application. 所以能少就少,尤其注意nested layout,一个方案是用relative layouts代替nested。也就是 flat instead of deep。

15) Hierarchy Viewer
SDK/tools: attach to any Android device, emulator, or physical phone  and then introspect(反省) the structure of the current view. 只对当前view反射下。
hierarchychyviewer.bat


16) 引出的问题,去掉action bar
activity 里加属性android:theme="@android:style/Theme.Holo.NoActionBar"  类似于这种无bar 的theme , 这个是level11的
android:theme="@android:style/Theme.NoTitleBar"

====================================================================
Chapter 7. Preferences, the Filesystem, the Options Menu, and Intents

7.1 Preferences
对于Yamba来说有username, password, API root
(1) Create a Preference resource file called prefs.xml
(2) Implement the PrefsActivity.java that inflates that resource file
(3) Register this new activity with the AndroidManifest.xml file
(4) Provider a way to start that activity from the rest of the application

PrefsActivity : preferece-aware activity, 现在都推荐用PreferenceFragment
*一些奇怪的错误,比如认为类does not extend android.app.Activity,这时就可以用Project->Clean, 或删除extends Activity 保存再回滚保存, 或重新写.PrefsActivity
Preferece中的配置,重启机子后都会仍存在。

SharedPreference 可以由activity,service, broadcast receiver, content provider等来读Preference

7.2 Options Menu
我们知道有个新的activity,怎么调呢?用Option Menu: 用户按Menu时,在屏幕底部出现
(1) Create the menu.xml resource where we specify what the menu consist of
(2) Add onCreateOptionsMenu() to the activity that should have this menu
(3) Provider handling of menu events in onOptionsItemSelected()

涉及系统资源问题,xml中用@android:drawable/ic_menu_preferences, java中用android.R instead of R
系统资源在:android-sdk/platforms/android-9/data/res  9可以为任何 version

onCreateOptionsMenu() : 点了menu时触发,之后一直没了,直到destroy
onOptionsItemSelected() : 点了

7.3 The Filesystem
打开两途径:
(1) via Eclipse
File Explorer: Window-> Show View-> other -> Android -> File Explorer
也可以DDMS
(2)via command line
adb shell

Filessytem Partitions - Three main parts:
(1) /system/ : 有applications, system libraries, android framework, linux commnad-line tools, and so on. 对应的system.img
(2) /sdcard/ : 具体路径可能是/mnt/sdcard, 对应sdcard.img
(3) /data/ : user data partition  , 这个最重要/data/data/

====================================================================
Chapter 8. Services
分为bound和unbound
bound service为更多的application提供服务,via an interafce called AIDL(Android Interafce Definition Language),只有两种状态Started / Stopped(Destroyed)
unbound service: yamba选用。

8.1 Application Object(项目公共类)
android.app.Application class, 本例中为YambaApplication, 这是application级的公共对象,这里把getTwitter()方法加到这里,使得整个application随时可以获得该对象。
(1) Create the Java class representing YambaApplication
(2) Register the new class with the AndroidManifest.xml file(告诉系统用YambaApplication而不是默认的application)
      修改manifest.xml下的application节点的android:name属性。

知识点:同步方法,Synchronized method
the synchronized means that only one thread can be inside of such a method at one time. 

8.1 UpdateService
不断的从网上的把内容拉下来保存到本地。步骤如下:
(1) create java class representing your service
(2) register the service in Android manifest file
(3) start the service


知识点: service 中,onbind 是用于bound service的。
     service的on create   只会在运行一次,在其生命周期中。
     service的start service方法,在接收到start service  intent时就会运行一次。会调用onStartCommand()


一个准则:任何事件与UI分离,在不同的Thread上。

注:为什么要在service中新建一个thread?
If we run our update operation on the default thread, any delay caused by the network update will cause our user interface to block. this in turn will make our application appear sluggish to the user and may even lead to the user and may even lead to Android system offering to kill our application by bringing up the “Force Close or Wait” dialog window.


====================================================================
Chapter 9. The Database

数据存在在本地数据库,定时从云中更新,从而提高用户体验。

9.1 SQLite
优点:
(1) zero configuration 
(2) it doesn’t have a server. no SQLite database process running.
(3) it’s a single file database
(4) it’s open source

知识点:android sets aside a special, secure sandbox for each application.
SQLite is by no means your only option , SQLite绝不是唯一的选择。可选JAVADB, MongoDB等。
SQLite is note an alternative to a full SQL server; instead, it is an alternative to using a local file with an arbitrary format.



9.2 DbHelper
Android中提供了类SQLiteOpenHelper用于extends。返回得到SQLiteDatabase实例。

9.2.1 Schema
A schema is just a description of what’s in a database.
对于Yamba可以建表如下:
ID: Identify
created_at : 啥时创建的。
txt : 内容
user: 谁创建的。

schema的创建会是在DbHelper的onCreate()方法中。CREATE TABLE
需要有Version从而更新Schema, ALTER TABLE 在DbHelper的onUpgrad()中。

9.2.2 Four Major Operations
CRUD: Create, Read(Query), Update, Delete.
DbHelper offers:
insert(), query(), update(), delete().

其他的直接用SQL:  execSQL()

9.2.3 Cursors
A query returns a set of rows along with a pointer called cursor.

知识点:SQL操作不可控,比如磁盘已满,所以最好所有SQL操作均以try catch包起来,以SQLExceptions处理。
     Eclipse中有方便的操作,选中代码,Source -> Surround with -> Try/Catch

知识点:显然的在java 类中的一个不加任何限定的参数不是private的。


9.2.4 sqlite3
adb shell
cd /data/data/com.mazei.yamba/databases/
sqlite3 timeline.db
.help  //查看帮助
.schema

9.2.5 创建StatusData而且使DBHelper成为其内部私有类的原因?
This is because it now makes sense to make DbHelper an inner class because DbHelper now exists only in the context of StatusData and is private to it.  In other words, outside of StatusData, no other part of the system is concerned with the fact that we are using a database to store our data. that also makes our system flexible.


====================================================================
Chapter 10. Lists and Adapters

有三个Activities and 一个Service
Timeline Activity: Pulls the data form the database and displays it on the screen.
     (1) uses a TextView to display all the output from the database.  use ScrollView to wrap our text.
     (2) the much more scalable and efficient  ListView and Adapter approach.
     (3) create custom Adapter

10.1 Basic TimelineActivity  && ScrollView
Layout: 用textview, 对于小数据量的没有问题。
ScrollView: Scrolling,只有一个Direct Child. 一般不需要id,因为不需要操作,往往横竖都是不是100%.

10.2 Adapter
要解决的问题是: 若数据很大,不能一次全load出来。数据一般是cursor或array
adapter come as subclass of CursorAdapter or ArrayAdapter. 

Timeline Adapter: Creating a new TimelineAdapter that is a subclass of SimpleCursorAdapter and overriding its bindView() method.

reference: http://developer.android.com/reference/android/widget/SimpleCursorAdapter.html


10.3 ViewBinder: A better alternative to Timeline Adapter
Attach the business logic directly to the existing SimpleCursorAdapter. using its setViewBinder() method.

10.4 action.MAIN && category.LAUNCHER
There is a special action named android.intent.action.MAIN that simply indicates this is the main component that should be started when the user wants to start your application.
Additionally, the <category> element tells the system that this application should be added to the main Launcher application so that the user can see its app icon along with all the other icons, click on it, and start it. This category is defined as android.intent.category.LAUNCHER.

 
====================================================================
Chapter 11. Broadcast Receivers

case1: create a broadcast receiver that will start up your update service at boot time. (BootReceiver)
case2: create a receiver that will update the timeline when it changes while the user is viewing it.
case3: app security by defining permissions

Broadcast receivers are Android’s implementation of the Publish/Subscribe messaging pattern, or more precisely, the Observer pattern.

intent broadcast
有三个Activities and 一个Service
Timeline Activity: Pulls the data form the database and displays it on the screen.
     (1) uses a TextView to display all the output from the database.  use ScrollView to wrap our text.
     (2) the much more scalable and efficient  ListView and Adapter approach.
     (3) create custom Adapter

查看运行的服务:Settings -> Applications -> Running Services.

对于case1:BootReceiver, 只需要在manifest.xml中配置。
对于case2:TimelineReceiver, 需要注册到activity的onResume()中,因为activity要到running状态,必须经过onResume方法。
     类似的,activity要到stopped 状态,必然要经过onPause()方法。
     对于new IntentFilter(“com.mazei.yamba.NEW_STATUS”)表示一个IntentFilter对象过滤com.mazei.yamba.NEW_STATUS intent action. (listening)
     
     broadcasting is at Updater class which is an inner class of UpdaterService

     不通过过滤注册成的receiver可能会接收到各种intent,并触发。

ERROR: trying to requery an already closed cursor
问题出在一个depresed方法上,
http://stackoverflow.com/questions/5915597/android-error-java-lang-illegalstateexception-trying-to-requery-an-already-clo

The Network Receiver: We’re limited by the battery life and network connectivity.

权限:
(1) sendBroadcast( Intent, receive_permission), 这个permission 就在manifest文件里配置,并use-permission,这样receiver就不受影响,因为有了这个权限,可以收到该broadcast
(2) registerReceiver( receiver, filter, send_permission, null).  这个是验证有没发的权限。





====================================================================
Chapter 12. Content Providers

Content Providers are Android building blocks that can expose data across the boundaries between application sandboxes.
Each application run in its own process with its own permissions.
How to share data across applications?

(1) Create a new Java class that subclasses the system’s ContentProvider class
(2) Declare your CONTENT_URI  (Uniform Resource Identifier)
     e.g. content://com.mazei.yamba.statusprovider/status/47
     PartA: content://  都要加的
     PartB: com. mazei . yamba.provider,  称为authority. 一般是类名。要与manifest.xml中匹配。
     PartC: status:  指明提供的数据类型。
     PartD: 47:  是个可选的ID。要整个数据此处不填。

(3) Implement all the unimplemented methods, such as insert(), update(), delete(), query(), getID(), and getType().
(4) Declare your content provider in the AndroidManifest.xml file

创建Widget: YambaWidget extends AppWidgetProvider
     AppWidgetProvider  这个是BroadcastReceiver的子类,这显然好理解。
     onUpdate常用,一般设置为何30分钟更新一次。


====================================================================
Chapter 13. System Services
like the Location service, Sensor service, WiFi service, Alarm service, Telephony service, Bluetooth service, and so on.

1. compass demo
注意到:在resume中注册,而在pause中unregister是为了当用户在看时才用。比如GPS服务,这样可以更省电。
因为进出必然通过resume与pause
 也有人选择{onStart, onStop} 甚至{onCreate, onDestroy}, 对于activity来说。

大部分跳过。

====================================================================
Chapter 14. The Android Interface Definition Language

Application之间交互,asynchronous method is  by Intent, synchronous method is Interprocess Communication(IPC)
Android有其自己的IPC protocol. 发送端整装称为:marshaling, 接收端解压称为:unmarshaling
为了实现这个Android 提供了Android Interface Definition Language, AIDL.
用AIDL 实现IPC, 类似于Java的语法。

服务端有.aidl文件。using AIDL.

Android provides an interprocess communication mechanism based on its binder, a high-performance, shared-memory system.
大部分跳过。

====================================================================
Chapter 15. The Native Development Kit (NDK)

NDK is an add-on to SDK that helps you integrate native code-code that uses platform - specific features, generally exposed through C or C++ language APIs -  with your Android Application. 


补充:
====================================================================
Chapter 8. Fragment 

In Android 3.0 (API Level 11), Android introduced the Fragments API. This was in response to a growing need to accommodate multiple screen sizes (such as tablets versus phones) and orientations (landscape versus portrait).  

To do this, it was necessary to modularize the views (the UI) such that it would be easy to separate the Activity con‐ tainer from the UI. 

1. The implementation:

(1) new_activity_status.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent" ]] ]]>
   
   
<fragment
       
android:id="@+id/fragment_status"
       
android:name="com.mazei.yamba.StatusFragment"
       
android:layout_width="match_parent"
       
android:layout_height="match_parent" />
   
</FrameLayout]] ]]>


(2) com.mazei.yamba.StatusFragement:
public class StatusFragment extends Fragment implements OnClickListener {
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {

          Log.d(
TAG, "onCreateView");
          View view = inflater.inflate(R.layout.
fragment_status, container, false);
          return view;
     }

}

(3) R.layout.fragment_status.xml : 原来的relative_layout
 
样例:




2. Fragment life cycle





important methods:
onCreateView()

onResume()

onPause()

onDestroyView()

3. Dynamically adding fragment

initialization of the fragment happens in an XML file, this is called static initialization.  

XML ultimately always becomes Java, so everything that can be done statically can also be done dynamically. 

        @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (savedInstanceState == null) {
Log.d(
TAG, "The saved instance state is null, this is the first time this activity is created");
StatusFragment fragment =
new StatusFragment();
getFragmentManager().beginTransaction()
.add(android.R.id.
content, fragment, fragment.getClass().getSimpleName())
.commit();
}
else {
Log.d(
TAG, "The saved instatce state is not null");
}
}


显然,直接切出返回,不会触发oncreate()。 we could also have gotten to this point in the code when the activity exists and the screen has been rotated by the user.

 attach this new fragment to the root of this activity identified by the system ID android.R.id.content

 

====================================================================
Chapter Additional  - HandlerThread  


Reference: http://developer.android.com/reference/android/os/HandlerThread.html
Handy class for starting a new thread that has a looper. The looper can then be used to create handler classes. Note that start() must still be called.


java.lang.Object
   ↳ java.lang.Thread
     ↳ android.os.HandlerThread

Inherited Constants
From class java.lang.Thread
int MAX_PRIORITY The maximum priority value allowed for a thread.
int MIN_PRIORITY The minimum priority value allowed for a thread.
int NORM_PRIORITY The normal (default) priority value assigned to the main thread.


Public Constructors
HandlerThread(String name)
HandlerThread(String name, int priority)
Constructs a HandlerThread.



Public Methods
Looper getLooper()
This method returns the Looper associated with this thread.
int getThreadId()
Returns the identifier of this thread.
boolean quit()
Quits the handler thread's looper.
boolean quitSafely()
Quits the handler thread's looper safely.
void run()
Calls the run() method of the Runnable object the receiver holds.

Protected Methods
void onLooperPrepared()
Call back method that can be explicitly overridden if needed to execute some setup before Looper loops.










[1] Android Reference: http://developer.android.com/reference/packages.html
[2] Android Development Tutorial based on android 4.4: http://www.vogella.com/tutorials/Android/article.html
[3] Architecting Android Apps : https://thenewcircle.com/s/post/1178/architecting_android_apps
     尤其包含了Chapter4的图与实现例子,似乎是本书作者的文章, Marko Gargenta @ Marakana
[4] 本书电子版在线:http://my.safaribooksonline.com/book/programming/android/9781449304881
[5] github 源码例子: https://github.com/twitter-university/LearningAndroidYamba
[6] http://yamba.marakana.com/api
[7] 本书中文在线版在:http://dev.icybear.net/learning-android-cn/book.html#toc82
[8] Video classes : https://thenewcircle.com/s/post/270/andevcon_android_for_java_developers