@Override
public boolean processMessage(Message msg) {
Log.d("BoringState", "");
return true;
}
}
class SleepState extends State {
@Override
public void enter() {
Log.d("SleepState", "enter Sleep");
}
@Override
public boolean processMessage(Message msg) {
switch (msg.what) {
case MSG_WAKEUP:
//睡觉醒了去⼯作,⼯作的时候收到饿了的讯号
sendMessage(obtainMessage(MSG_HUNGRY)); deferMessage(msg);
transitionTo(mWorkState);
break;
case MSG_HALTING:
transitionToHaltingState();
break;
default:
return false;
}
return true;
}
@Override
public void exit() {
Log.d("SleepState", "exit Sleep");
}
}
@Override
protected void onHalting() {
Log.d("PersonStateMachine", "halting");
synchronized (this) {
}
}
class WorkState extends State {
@Override
public void enter() {
Log.d("WorkState", "enter Work");
}
@Override
public boolean processMessage(Message msg) {
switch (msg.what) {
case MSG_HUNGRY:
//⼯作饿了去吃饭,吃饭的时候收到累了的讯号
sendMessage(obtainMessage(MSG_TIRED));
deferMessage(msg);
transitionTo(mEatState);
break;
default:
return false;
switch函数用法举例
}
return true;
}
@Override
public void exit() {
Log.d("WorkState", "exit Work");
}
}
class EatState extends State {
以上图中,初始状态为S4,现在⽬标状态mDestState被设置为S7。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论