Thread already started- trans data via bluetooth
<p>This is my : bluetooth.java. When I test my app, its jumps out this errors "Thread are already started. Then I can't sent my data anymore, then i get out of my app, then I start my app again, then it allows my to use app. 
So confusing.
I hope you will help me.
Thank for your help .</p>

<pre><code>public class bluetooth extends AppCompatActivity {

// SPP UUID service
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
// MAC-address of Bluetooth module (you must edit this line)
private static String address ;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bluetooth);
    on = (ImageView) findViewById(R.id.btn_enable);
    find = (ImageView) findViewById(R.id.btn_scan);
    mPairedBtn = (ImageView) findViewById(R.id.btn_view_paired);
    BA = BluetoothAdapter.getDefaultAdapter();
    mProgressDlg = new ProgressDialog(this);
    back =(ImageView) findViewById(R.id.backblue);
    ontext = (TextView) findViewById(R.id.connecttext);

    back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(bluetooth.this,MainActivity.class);
            startActivity(intent);
        }
    });



    //xử lí các nút
    if (BA == null) {
        showUnsupported();
    } else {
        mPairedBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Set&lt;BluetoothDevice&gt; pairedDevices = BA.getBondedDevices();

                if (pairedDevices == null || pairedDevices.size() == 0) {
                    showToast("No Paired Devices Found");
                } else {
                    ArrayList&lt;BluetoothDevice&gt; list = new ArrayList&lt;BluetoothDevice&gt;();

                    list.addAll(pairedDevices);

                    Intent intent = new Intent(bluetooth.this, DeviceListActivity.class);

                    intent.putParcelableArrayListExtra("device.list", list);

                    startActivity(intent);
                }
            }
        });

        find.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                BA.startDiscovery();
            }
        });

        on.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (BA.isEnabled()) {
                    BA.disable();
                    showDisabled();
                   /* try
                    {
                        btSocket.close();
                    } catch (IOException e2)
                    {

                    }*/
                    on.setImageResource(R.drawable.offlight);

                } else {
                    Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

                    startActivityForResult(intent, 1000);

                    on.setImageResource(R.drawable.onlight);

                }
            }
        });

        if (BA.isEnabled()) {
            showEnabled();

        } else {
            showDisabled();
        }
    }

    //thong bao cho may la chuong trinh nay co he su dung dc gi bluetooth
    IntentFilter filter = new IntentFilter();

    filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    filter.addAction(BluetoothDevice.ACTION_FOUND);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    /* BroadcastReceiver dùng để nhận các intent từ hệ thống hoặc trao đổi dữ liệu giữa hai hay nhiều ứng dụng.*/
    registerReceiver(mReceiver, filter);


    // MAC-address of Bluetooth module (you must edit this line)
    address = "30:14:10:09:07:86";

    //create device and set the MAC address
    BluetoothDevice device = BA.getRemoteDevice(address);

    try {
        btSocket = createBluetoothSocket(device);
    } catch (IOException e) {
        Toast.makeText(getBaseContext(), "Socket creation failed", Toast.LENGTH_LONG).show();
    }
    // Establish the Bluetooth socket connection.
    //btSocket.connect();
    try
    {
        btSocket.connect();
    } catch (IOException e) {
        try
        {
            btSocket.close();
        } catch (IOException e2)
        {
            //insert code to deal with this
            Toast.makeText(getApplicationContext(),"cant do this",Toast.LENGTH_LONG).show();
        }
    }

    ConnectedThread.createInstance(btSocket);


    //I send a character when resuming.beginning transmission to check device is connected
    //If it is not an exception will be thrown in the write method and finish() will be called
    if(ConnectedThread.getInstance()!= null){
        ConnectedThread.getInstance().start();
    }else {
        ConnectedThread.getInstance().cancel();
    }


}

@Override
public void onResume() {
    super.onResume();



}

private BluetoothSocket createBluetoothSocket(BluetoothDevice device) throws IOException {

    return  device.createRfcommSocketToServiceRecord(MY_UUID);
    //creates secure outgoing connecetion with BT device using UUID
}

@Override
public void onPause() {
    super.onPause();

}

@Override
public void onDestroy() {
    unregisterReceiver(mReceiver);
    super.onDestroy();
}




private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
            final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);

            if (state == BluetoothAdapter.STATE_ON) {
                showToast("Enabled");

                showEnabled();
            }
        } else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
            mDeviceList = new ArrayList&lt;BluetoothDevice&gt;();

            mProgressDlg.show();
        } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            mProgressDlg.dismiss();

            Intent newIntent = new Intent(bluetooth.this, DeviceListActivity.class);

            newIntent.putParcelableArrayListExtra("device.list", mDeviceList);

            startActivity(newIntent);
        } else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            BluetoothDevice device = (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            mDeviceList.add(device);

            showToast("Found device " + device.getName());
        }
    }
};
</code></pre>

<p>}</p>