StatMachine的removeState方法用于从这个状态机中删除一个状态,代码如下:
//frameworks/base/core/java/com/android/internal/util/StateMachine.java
public class StateMachine {
private SmHandler mSmHandler;
public final void removeState(State state) {
mSmHandler.removeState(state);
}
}
调用SmHandler的removeState方法:
//frameworks/base/core/java/com/android/internal/util/StateMachine.java
public class StateMachine {
private static class SmHandler extends Handler {
/** The map of all of the states in the state machine */
private HashMap<State, StateInfo> mStateInfo = new HashMap<State, StateInfo>();
private void removeState(State state) {
StateInfo stateInfo = mStateInfo.get(state); //通过mStateInfo取得state对应的stateInfo
if (stateInfo == null || stateInfo.active) {
return;
}
// 判断是否是父简单,如果是直接返回
boolean isParent = mStateInfo.values().stream()
.filter(si -> si.parentStateInfo == stateInfo)
.findAny()
.isPresent();
if (isParent) {
return;
}
mStateInfo.remove(state); //调用mStateInfo的remove方法删除state
}
}
}