R
R
RomanoO2012-03-29 11:13:13
Android
RomanoO, 2012-03-29 11:13:13

How are BluetoothDevice and BT adapter status (on / off) related?

Good afternoon, Habr!

Faced the following problem:
there is a piece of code like this:
private HashSet discoveredDevices;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//....
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (savedInstanceState == null) {
discoveredDevices = new HashSet();
} else {
discoveredDevices = (HashSet) savedInstanceState
.getSerializable("devices");
for (BluetoothDevice device : discoveredDevices) {
adapter.add(device.getName() + "\n" + device.getAddress());
}
}
//....
}

И код сохранения состояния:
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable("devices", discoveredDevices);
}

Если отключить БТ и повернуть экран (т.е. попасть в обработчик onActivityCreated), то на этом месте:
discoveredDevices = (HashSet) savedInstanceState.getSerializable("devices");

программа вылетает.
Может кто-нибудь объяснить, почему так происходит?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
debugger88, 2012-03-29
@debugger88

Well, where are the logs?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question