title: Android bluetooth communication
body: <p>I make a project that send strings from bluetooth to other bluetooth device. My question is that i if i make a connection to bluetooth device in first activity, do i need to make it again for second activity?  </p>
  
  <pre><code>private ProgressDialog progress;
  public BluetoothAdapter myBluetooth = null;
  public static BluetoothSocket btSocket = null;
  private boolean isBtConnected = false;
  static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
  @Override
  protected void onCreate(Bundle savedInstanceState)
     {
      super.onCreate(savedInstanceState);
  
      Intent newint = getIntent();
      address = newint.getStringExtra(DeviceList.EXTRA_ADDRESS);
  
      setContentView(R.layout.activity_led_vent_control);
      init();
  
      leds1 = (Switch) findViewById(R.id.switch1);
      leds2 = (Switch) findViewById(R.id.switch2);
      leds3 = (Switch) findViewById(R.id.switch3);
      leds4 = (Switch) findViewById(R.id.switch4);
      leds5 = (Switch) findViewById(R.id.switch5);
      brightness = (SeekBar)findViewById(R.id.seekBar);
      lumn=(TextView)findViewById(R.id.lumn);
      btnDis=(Button)findViewById(R.id.btnDis);
  
  
      new ConnectBT().execute(); //Call the class to connect
  
      //commands to be sent to bluetooth
      leds1.setOnClickListener(new View.OnClickListener()
      {
          @Override
          public void onClick(View v)
          {
              if(leds1.isChecked())
              turnOnLed1();      //method to turn on
              else turnOffLed1();
          }
      });
       }
      private void turnOnLed1()
  {
      if (btSocket!=null)
      {
          try
          {
              btSocket.getOutputStream().write("A".toString().getBytes());
              l1=true;
          }
          catch (IOException e)
          {
              msg("Error");
          }
      }
  }
  </code></pre>