protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
search = (Button) findViewById(R.id.search);
connect = (Button) findViewById(R.id.connect);
listView = (ListView) findViewById(R.id.listview);
if (savedInstanceState != null) {
ArrayList<BluetoothDevice> list = savedInstanceState.getParcelableArrayList(DEVICE_LIST);
if (list != null) {
initList(list);
MyAdapter adapter = (MyAdapter) listView.getAdapter();
int selectedIndex = savedInstanceState.getInt(DEVICE_LIST_SELECTED);
if (selectedIndex != -1) {
adapter.setSelectedIndex(selectedIndex);
connect.setEnabled(true);
}
} else {
initList(new ArrayList<BluetoothDevice>());
}
} else {
initList(new ArrayList<BluetoothDevice>());
}
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
mBTAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBTAdapter == null) {
Toast.makeText(getApplicationContext(), "Bluetooth not found", Toast.LENGTH_SHORT).show();
} else if (!mBTAdapter.isEnabled()) {
Intent enableBT = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBT, BT_ENABLE_REQUEST);
} else {
new SearchDevices().execute();
}
}
});
connect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
BluetoothDevice device = ((MyAdapter) (listView.getAdapter())).getSelectedItem();
Intent intent = new Intent(getApplicationContext(), Controlling.class);
intent.putExtra(DEVICE_EXTRA, device);
intent.putExtra(DEVICE_UUID, mDeviceUUID.toString());
intent.putExtra(BUFFER_SIZE, mBufferSize);
startActivity(intent);
}
});
MainActivity코드입니다. 블루투스 장치목록에서 연결버튼을 누르면 충돌이 일어나서
작동이 중지되는데
이유가 false선언을 해주지않아서 충돌이 일어나는것같은데
어디에다가 선언을 해야 될지 몰라서 질문을 드립니다.