overridePendingTransition的执行流程
分类:Android, Java, Uncategorized
阅读 (1,445)
Add comments
2月 202018
具体请看下面的表格:
1 2 3 4 5 6 7 |
public void overridePendingTransition(int enterAnim, int exitAnim) { try { ActivityManagerNative.getDefault().overridePendingTransition( mToken, getPackageName(), enterAnim, exitAnim); } catch (RemoteException e) { } } |
♠ frameworks/base/core/java/android/app/ActivityManagerNative.java
§ ActivityManagerNative.getDefault() 很简单,获取gDefault | ||
|
||
§ gDefault 一个静态变量,是ActivityManagerService 的代理对象 | ||
|
♠ frameworks/base/services/java/com/android/server/am/ActivityManagerService.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
@Override public void overridePendingTransition(IBinder token, String packageName, int enterAnim, int exitAnim) { synchronized(this) { ActivityRecord self = ActivityRecord.isInStackLocked(token); if (self == null) { return; } final long origId = Binder.clearCallingIdentity(); if (self.state == ActivityState.RESUMED || self.state == ActivityState.PAUSING) { mWindowManager.overridePendingAppTransition(packageName, enterAnim, exitAnim, null); } Binder.restoreCallingIdentity(origId); } } |
ActivityRecord.isInStackLocked(token); 查询当前Activity是否还在Activity栈中? | ||
|
||
如果还在继续执行Binder.clearCallingIdentity();保存此Activity在Binder中的id,稍候就会使用overridePendingAppTransition执行恢复的操作。 | ||
如果当前Activity的状态是活动状态或者将要暂停状态,执行WindowManagerService的overridePendingAppTransition |
♠ frameworks/base/services/java/com/android/server/wm/WindowManagerService.java
1 2 3 4 5 6 7 8 |
@Override public void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim, IRemoteCallback startedCallback) { synchronized(mWindowMap) { mAppTransition.overridePendingAppTransition(packageName, enterAnim, exitAnim, startedCallback); } } |
调用AppTransition的overridePendingAppTransition方法(将动画的设置信息都放在AppTransition中了) | ||
|
||
然后WindowManagerService在进行Activity切换的时候就会根据AppTransition的动画设置来显示切换动画了。 |
总结:
1. 执行overridePendingTransition时的调用顺序ActivityManageService->WindowManageService
2. 最终设置的是WindowManagerService的overridePendingAppTransition
3. 和Windows编程中显示模式窗口不同,执行startActivity时并没有立即暂停当前Activity,而是通过Handler在下一个MessageQueue的处理中暂停的当前Activity