【凯子哥带你学Framework】Activity启动过程全解析
http://blog.youkuaiyun.com/zhaokaiqiang1992/article/details/49428287
简单说Binder(1)
http://blog.youkuaiyun.com/cauchyweierstrass/article/details/50701102
和一些被百度,腾讯面试上的面试题
http://blog.youkuaiyun.com/cauchyweierstrass/article/details/51220540
在联想工作的软件工程师
http://gityuan.com/2016/04/16/kill-signal/
前言:
ActivityManagerService和PackageManagerService都运行在系统进程System中,那么,这些运行在不同进程中的应用程序组件和系统组件是如何通信的呢?
直观来说,Binder是Android中的一个类,它继承了IBinder接口,从IPC角度来说,Binder是Android中的一种跨进程通信方式,Binder还可以理解为一种虚拟的物理设备,它的设备驱动是/dev/binder,它通信方式在Linux中没有,从Android Framework角度来说,Binder是ServiceManager连接各种Manager(ActivityManager、WindowManager,等等)和相应ManagerService的桥梁;
Android开发中,Binder主要用于在Service中,包括AIDL和Messager
现在我们实例讲解一下,使用AIDL来分析Binder的工作机制。
- 新建java包 com.ryg.chapter_2.aidl
- 然后新建三个文件Book.java、Book.aidl和IBookManager.aidl代码如下
Book.java // 一个表示图书信息的类
public class Book implements Parcelable {
public int bookId;
public String bookName;
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.bookId);
dest.writeString(this.bookName);
}
public Book() {
}
protected Book(Parcel in) {
this.bookId = in.readInt();
this.bookName = in.readString();
}
public static final Parcelable.Creator<Book> CREATOR = new Parcelable.Creator<Book>() {
@Override
public Book createFromParcel(Parcel source) {
return new Book(source);
}
@Override
public Book[] newArray(int size) {
return new Book[size];
}
};
}
Book.aidl // 是Book类在AIDL中的声明
package com.example.lijinhua.frameworkbinder.book.aidl;
Parcelable Book;
// IBookManager.aidl是我们定义的一个接口,这里的Book需要显示的import这就是aidl的特殊之处
package com.example.lijinhua.frameworkbinder.book.aidl;
import com.example.lijinhua.frameworkbinder.book.aidl.Book;
interface IBookManager {
List<Book> getBookList();
void addBook(in Book book);
}