public void handleMessage(Message msg) {
switch (msg.what) {
case DESTROY_ACTIVITY:
handleDestroyActivity((IBinder)msg.obj, msg.arg1 != 0,
msg.arg2, false);
break;
}
}
handleMessage方法中调用了handleDestroyActivity方法,如下所示:
private void handleDestroyActivity(IBinder token, boolean finishing,
int configChanges, boolean getNonConfigInstance) {
…省略
if (finishing) {
try {
ActivityManager.getService().activityDestroyed(token);
} catch (RemoteException ex) {
throw ex.rethrowFromSystemServer();
}
}
mSomeActivitiesChanged = true;
}
handleDestroyActivity方法最终调用了ActivityManagerService的activityDestroyed方法。
2.2、分析阶段2
承接上面的逻辑,我们跳转到ActivityManagerService,并找到activityDestroyed方法,如下所示:
public final void activityDestroyed(IBinder token) {
synchronized (this) {
ActivityStack stack = ActivityRecord.getStackLocked(token);
if (stack != null) {
stack.activityDestroyedLocked(token, “activityDestroyed”);
}
}
}
在activityDestroyed方法中,通过ActivityRecord.getStackLocked方法获取一个ActivityStack对象,并调用ActivityStack的activityDestroyedLocked