В моята дейност имам това:
protected void onStart() {
super.onStart();
blc = new BluetoothClient(this);
}
protected void onStop() {
super.onStop();
try {
blc.close();
} catch (IOException e) { }
blc = null;
}
Това е класът, който има приемника: (Само важните части)
public class BluetoothClient implements Closeable {
final BroadcastReceiver receiver;
Context context;
...
public BluetoothClient(Context context) {
this.context = context.getApplicationContext();
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
}
};
context.registerReceiver(receiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
...
}
...
public void close() throws IOException {
try {
context.unregisterReceiver(receiver); // Causes IllegalArgumentException
} catch (Exception e) {
e.printStackTrace();
}
}
}
Получавам java.lang.IllegalArgumentException: Receiver not registered
всеки път в BluetoothClient.close. Как мога да направя това правилно.
Редактиране: добавен е целият код (вероятно е твърде много, за да се прегледа с един поглед)
пълният код (с изключение на основната дейност, забравих за това) е тук: http://pastebin.com/aVit2L8M
основна дейност: http://pastebin.com/6Ww8sKwE
context
вclose()
метод? - person ρяσѕρєя K   schedule 29.09.2015