stateMachine状态转换流程(transitionTo)

这篇博客详细探讨了Android应用程序中使用Java实现stateMachine的状态转换过程,重点讲解了transitionTo方法在状态切换中的应用及其流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

stateMachine状态转换流程

/packages/apps/Bluetooth/src/com/android/bluetooth/pbapclient/PbapClientStateMachine.java
351    public void disconnect(BluetoothDevice device) {
   
   
352        Log.d(TAG, "Disconnect Request " + device);
353        sendMessage(MSG_DISCONNECT, device);
354    }
/frameworks/base/core/java/com/android/internal/util/StateMachine.java
1713    /**
1714     * Enqueue a message to this state machine.
1715     *
1716     * Message is ignored if state machine has quit.
1717     */
1718    public void sendMessage(int what, Object obj) {
   
   
1719        // mSmHandler can be null if the state machine has quit.
1720        SmHandler smh = mSmHandler;
1721        if (smh == null) return;
1722
1723        smh.sendMessage(obtainMessage(what, obj)); // private static class SmHandler extends Handler
1724    }
/frameworks/base/core/java/android/os/Handler.java
593    /**
594     * Pushes a message onto the end of the message queue after all pending messages
595     * before the current time. It will be received in {@link #handleMessage},
596     * in the thread attached to this handler.
597     *
598     * @return Returns true if the message was successfully placed in to the
599     *         message queue.  Returns false on failure, usually because the
600     *         looper processing the message queue is exiting.
601     */
602    public final boolean sendMessage(Message msg)
603    {
   
   
604        return sendMessageDelayed(msg, 0);
605    }
/frameworks/base/core/java/com/android/internal/util/StateMachine.java
787        /**
788         * Handle messages sent to the state machine by calling
789         * the current state's processMessage. It also handles
790         * the enter/exit calls and placing any deferred messages
791         * back onto the queue when transitioning to a new state.
792         */
793        @Override
794        public final void handleMessage(Message msg) {
   
   
795            if (!mHasQuit) {
   
   
796                if (mSm != null && msg.what != SM_INIT_CMD && msg.what != SM_QUIT_CMD) {
   
   
797                    mSm.onPreHandleMessage(msg);
798                }
799
800                if (mDbg) mSm.log("handleMessage: E msg.what=" + msg.what);
801
802                /** Save the current message */
803                mMsg = msg;
804
805                /** State that processed the message */
806                State msgProcessedState = null;
807                if (mIsConstructionCompleted || (mMsg.what == SM_QUIT_CMD)) {
   
   
808                    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值