Android开发中经常会遇到对一个流程中不同状态的定义,个人通常有两种定义方式:一种是用Enum,另一张就是直接定义在状态类中了,例如WebSocket的使用过程中有如下状态:正在连接、已连接、重连接和未连接着四种状态,WebSocket的关闭也分为正常关闭和非正常关闭两种状态,该状态类就可以定义如下:
public class WsStatus {
public final static int CONNECTED = 1;
public final static int CONNECTING = 0;
public final static int RECONNECT = 2;
public final static int DISCONNECTED = -1;
class CODE {
public final static int NORMAL_CLOSE = 1000;
public final static int ABNORMAL_CLOSE = 1001;
}
class TIP {
public final static String NORMAL_CLOSE = "normal close";
public final static String ABNORMAL_CLOSE = "abnormal close";
}
}