AMS端向目标进程发送目标Activity的数据:
frameworks/base/core/java/android/app/ApplicationThreadative.java
scheduleLaunchActivity(...) {
Parcel data = Parcel.obtain();
...
intent.writeToParcel(data, 0);
data.writeStrongBinder(token);
data.writeInt(ident);
info.writeToParcel(data, 0);
data.writeBundle(state);
data.writeTypedList(pendingResults);
data.writeTypedList(pendngNewIntents);
data.writeInt(notResumed ? 1 : 0);
data.writeInt(isForward ? 1 :0);
mRemote.transact(SCHEDULE_LAUNCH_ACTIVITY_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
data.recycle();
}
目标进程接收目标Activity的数据:
frameworks/base/core/java/android/app/ApplicationThreadative.java
public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
throws RemoteException {
Intent intent = Intent.CREATOR.createFromParcel(data);
IBinder b = data.readStrongBinder();
int ident = data.readInt();
ActivityInfo info = ActivityInfo.CREATOR.createFromParcel(data);
Bundle state = data.readBundle();
<ResultInfo> ri = data.createTypedArrayList(ResultInfo.CREATOR);
<Intent> pi = data.createTypedArrayList(Intent.CREATOR);
boolean notResumed = data.readInt() != 0;
boolean isForward = data.readInt() != 0;
scheduleLaunchActivity(intent, b, ident, info, state, ri, pi,notResumed, isForward);
return true;
}
目标进程后续的处理:
1. 将加载目标Activity的请求增加到消息队列
frameworkds/base/core/java/android/app/ActivityThread.java
public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident, ....) {
ActivityClientRecord r = new ActivityClientRecord();
r.token = token;
r.ident = ident;
r.intent = intent;
r.activityInfo= info;
r.state = state;
r.pendingResuts = pendingResults;
r.pendingIntents = pendingNewIntents;
r.startsNotResumed = notResumed;
r.isForward = isForward;
queneOrSendMessage(H.LAUNCH_ACTIVITY, r);
}
2.从消息队列中取元素,处理Activity加载请求
frameworkds/base/core/java/android/app/ActivityThread.java
public void handleMessage(Message msg) {
switch (msg.what) {
case LAUNCH_ACTIVITY: {
ActivityClientRecord r = (ActivityClientRecod)msg.obj;
r.packageInfo= getPackageInfoNoCheck(r.activityInfo.applicationInfo);
handleLaunchActivity(r, null);
} break;
........
}
}