Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 处理程序中获取消息(intwhat,intarg1,intarg2)方法的任务是什么_Java_Android - Fatal编程技术网

Java 处理程序中获取消息(intwhat,intarg1,intarg2)方法的任务是什么

Java 处理程序中获取消息(intwhat,intarg1,intarg2)方法的任务是什么,java,android,Java,Android,我是一名初学者,试图理解BluetoothChat源代码。在BluetoothChatService中,我面临一些需要理解的问题 public static final int STATE_NONE = 0; // we're doing nothing public static final int STATE_LISTEN = 1; // now listening for incoming connections mState = STATE_NONE; privat

我是一名初学者,试图理解BluetoothChat源代码。在BluetoothChatService中,我面临一些需要理解的问题

public static final int STATE_NONE = 0;       // we're doing nothing
public static final int STATE_LISTEN = 1;     // now listening for incoming connections
mState = STATE_NONE;

private synchronized void setState(int state) {
    if (D) Log.d(TAG, "setState() " + mState + " -> " + state);
    mState = state;

// Give the new state to the Handler so the UI Activity can update
mHandler.obtainMessage(BluetoothChat.MESSAGE_STATE_CHANGE, state, -1).sendToTarget();
} 当我允许蓝牙打开时,在logcat中会显示
“setState()0->1”
。但我无法理解状态如何变成“1”

在android官方网站上,我发现了一个方法,它由3个参数组成,比如-
obtainMessage(int-what,int-arg1,int-arg2)
有人能解释一下这个获得的信息是如何工作的吗

Java专家需要您的帮助才能理解上述内容。

理解: 例如,您的计算机中有一个处理程序

在onCreate(BundlesavedInstanceState)中

我们知道ui线程或应用程序的主线程 有其内在机制

我们不必像对其他线程那样做 我们有另一个类,它有一个工作线程(用户线程) 定义的线程)

在上面的代码中,uiHandler.obtainMessage()的用途 就是我们知道ui线程与 消息队列。向该消息队列发送消息 我们需要该消息队列中某个单元格的地址

          uiHandler.obtainMessage();/*takes an  
       address of that cell(Message object) and
    gives that to message.*/
最后

       uiHandler.sendMessage(message) /*sends the 
       message to message queue.*/
尝试将您的查询与此关联,然后进行访问
希望这有帮助

这是Android API吗?如果是,请相应地标记。对不起,现在它已被编辑。
     public class MyThread {
           Thread thread=new Thread(new 
         Runnable(){
                @Override
                    public void run(){
                 Message 
               message=uiHandler.obtainMessage(); 
                     ///
                       ///
                      uiHandler.sendMessage(message);         
                     }  
                    }).start();
             } 
          uiHandler.obtainMessage();/*takes an  
       address of that cell(Message object) and
    gives that to message.*/
       uiHandler.sendMessage(message) /*sends the 
       message to message queue.*/