omaraflak / Bluetooth-Library

Bluetooth client library for Android.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Receiver never unregister

mr0bles opened this issue · comments

I'm trying to implement in many activity but have a problem, the coneccion never close and i receiver after back (i tested to change the onStart to onResume and onStop to onPause) and this block the connexion in the second activity (the socket it's allways bussy after the first connexion)

Activity

public class TestActivity extends AppCompatActivity implements TestView {
...
 @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      
        DaggerPesosComponent.builder()
                .bluetoothModule(MyApp.getInstance().bluetoothModule())
                .pesosModule(new TestModule(this))
                .build().inject(this);
...

 @Override
    protected void onStart() {
        super.onStart();
        presenter.onStart(this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        presenter.onStop();
    }
...

Presenter

 @Override
        public void onMessage(String message) {
            Log.i("DATA", message);
        }
@Override
    public void onStart(Activity activity) {
        interactor.onStart(bluetoothCallback, activity);
        if (interactor.isBluetoothEnabled()) {
            interactor.connectToDevice(device, communicationCallback);
            view.setStatus(R.string.bluetooth_connecting);
        } else {
            interactor.enableBluetooth();
        }
    }


    @Override
    public void onStop() {

        handler.removeCallbacks(runnable);
        interactor.onStop();
        communicationCallback = null;

    }

Interactor

@Override
    public void onStart(BluetoothCallback bluetoothCallback, Activity activity) {
        bluetooth.onStart();
        bluetooth.setCallbackOnUI(activity);
        bluetooth.setBluetoothCallback(bluetoothCallback);
    }

    @Override
    public void onStop() {
        bluetooth.onStop();
    }