title: Send data from two differents activities via bluetooth
body: <p>I´m trying to send data from two differents activities via bluetooth. But I have no success.
  This is my code:</p>
  
  <pre><code> public class MainActivity extends Activity {
  
  private BluetoothDevice btDevice;
  private CommunicationThread cmThread = null;
  
  
  TextView y;
      private static final UUID sppUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
  
  
  Button  activityci, dato1;
  TextView texto;
  int count=0; 
  
  @Override
     public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      activityci=(Button)findViewById(R.id.idboton);
      texto=(TextView)findViewById(R.id.idtexto);
  
      activityci.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              Intent comenzarPrincipal = new Intent(getBaseContext(), SegundoActivity.class);
  
              startActivity(comenzarPrincipal);
  
  
              cmThread.write((char)120);
  
  
  
  
  
          }
      });
  
  
      this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  
      Intent startIntent = this.getIntent();
      String btDevAddress = startIntent.getStringExtra(BuscarDispositivos.EXTRA_DEV_ADDRESS);
  
      btDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(btDevAddress);
  
      BluetoothSocket btSocket = null;
      try 
      {
                      btSocket = btDevice.createRfcommSocketToServiceRecord(sppUUID);
          cmThread = new CommunicationThread(btSocket);
          cmThread.start();
  
      } 
      catch (Exception e) 
      {
          Toast.makeText(this, "Necesita Conectarse!", Toast.LENGTH_SHORT).show();
          finish();
          return;
      }
  }
  
  
  }]
  
  &lt;/i&gt;
  </code></pre>
  
  <p>And my second activity:</p>
  
  <pre><code>      public class SegundoActivity extends Activity {
  private CommunicationThread cmthread=null;
  Button btn2;
  TextView text2;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.prueba2);
  
      btn2=(Button)findViewById(R.id.idboton2);
      text2=(TextView)findViewById(R.id.idtexto2);
  
      btn2.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
  
              int dato=250;
              char data=(char)dato;
              text2.setText(""+dato);
  
              cmthread.write(data);
  
  
  
          }
      });
  
  
  
  }
  
  
   }
  </code></pre>
  
  <p>From the first activity i can send data via bluetooth. But when i send from the second activity, i get error.
  Somebody knows what is the problem with this code?</p>