构造函数中:
mServerThread = new Thread(this);
mServerThread.start();
请问, 建立线程启动线程之后, 线程代码是不是在 public void run()函数 中?
package com.xxxx.xxxxx.transport;
class FileServerChannel implements FileChannel, Runnable {
private BluetoothServerSocket mServerSocket;
private BluetoothSocket mClient;
private Thread mServerThread;
private boolean mClosed = false;
private final Handler mHandler;
private final Context mContext;
FileServerChannel(Handler handler, Context context) throws IOException {
mContext = context;
mHandler = handler;
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
mServerSocket = adapter.listenUsingInsecureRfcommWithServiceRecord(
FileChannelManager.FILE_NAME, FileChannelManager.FILE_UUID);
mServerThread = new Thread(this);
mServerThread.start();
}
@Override
public void run() {
BluetoothSocket clnt = null;
while (!mServerThread.isInterrupted() && !mClosed) {
}
}
}
------解决思路----------------------
mServerThread.start(); 语句之后,就会运行 public void run().
可加log信息跟踪调试.