-1

I'm using a lib Android-BluetoothSPPLibrary (https://github.com/akexorcist/Android-BluetoothSPPLibrary)

I am creating an application to communicate with the Arduino.

I have two activities. The first to connect to the device. The second to send and receive data.

That part when the Bluetooth is connected and calls the second activity.

public void onDeviceConnected(String s, String s1) {
            Intent intent = new Intent(getApplicationContext(), MainActivity.class);
            intent.putExtras(bundle);
            startActivity(intent);
        }

The Bluetooth connects but when going to the second activity it disconnects, but the light is still on and was connected for the first activity.

1 Answers1

0

When you start the second activity, you inevitably stop the first one, which then breaks your connection socket.

Connection may still look as active on your Arduino until all resources from your activity are finally cleared from memory, which will effectively kill the connection that was improperly closed on runtime.

What you need is to hold your BluetoothSPP declaration globally, independent from Activity lifecycle.

MVojtkovszky
  • 519
  • 4
  • 11
  • Thanks for the answer. Any tips on how to do this ? Instantiate a global object ? – Diego Augusto Moura Sep 21 '15 at 17:53
  • Declare it in Application class, and then access it via a getter method anywhere in app. Refer to this for example: http://stackoverflow.com/questions/18002227/why-extend-an-application-class – MVojtkovszky Sep 22 '15 at 10:36