1

I've got a short question. How can I update a TextField without using an AsyncTask? In my Activity class I've got a function like this:

private void CheckBlueToothState(){

      if (bluetoothAdapter == null){
            status.setText("Bluetooth NOT support.");
        }else{
            if (bluetoothAdapter.isEnabled()){
                if(bluetoothAdapter.isDiscovering()){
                    status.setText("Bluetooth is currently in device discovery process.");
                }else{
                    status.setText("Bluetooth is Enabled");
                    search.setEnabled(true);
                }
            }else{
                status.setText("Bluetooth is NOT Enabled");
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
            }
        }
    }

Which checks if device got Bluetooth, is it enabled or disabled, you hopefully got the picture. So over to my question once again. How can I dynamically change the textfield status if I turn of the bluetooth, and vice versa?

Tobias Moe Thorstensen
  • 8,861
  • 16
  • 75
  • 143

1 Answers1

6

Register BroadcastReceiver with intent action BluetoothAdapter.ACTION_STATE_CHANGED and move your text updating code into onReceive method.

Example code could be found here.

Community
  • 1
  • 1
Caner
  • 57,267
  • 35
  • 174
  • 180