我想编辑Android BluetoothChat 示例,以便能够将其与多项活动一起使用。因此,我创建了一个扩展应用程序的类,作为here
的建议public class cBaseApplication extends Application {
public static cBaseApplication context;
private BluetoothChatService mBluetoothConnectedThread;
// Local Bluetooth adapter
private static BluetoothAdapter mBluetoothAdapter = null;
@Override
public void onCreate() {
super.onCreate();
context = this;
// Get local Bluetooth adapter
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}
public BluetoothChatService getBluetoothConnectedThread() {
return mBluetoothConnectedThread;
}
public void setBluetoothConnectedThread(BluetoothChatService mBluetoothConnectedThread) {
this.mBluetoothConnectedThread = mBluetoothConnectedThread;
}
public static BluetoothAdapter getBluetoothAdapter() {
return mBluetoothAdapter;
}
}
我遇到的问题是:将所需的代码从原始的BluetoothChat类移动到新的应用程序类。
即
// Initialize the BluetoothChatService to perform bluetooth connections
mChatService = new BluetoothChatService(this, mHandler);