'Arduino not receiving Bluetooth GATT signal

On my android studio app, I have a button that when pressed, sends a "go" signal and on release sends a "stop" signal.

When you hold the button down and then release it works fine with the Arduino receiving both signals. However, when it is a quick tap, the Arduino does not receive the stop signal.

I have checked that the signal is in fact being sent as I put a log message whenever this happens so it must be a problem with the Arduino not the app not detecting button presses.

Here is the code:

ImageButton fwdBtn = (ImageButton) findViewById(R.id.fwd);
fwdBtn.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View view, MotionEvent event) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.performClick();
                sendSignal("fwd");
                return true;
            case MotionEvent.ACTION_UP:
                sendSignal("stop");
                return true;
        }
        return false;
    }
});

private void sendSignal(String signal) {
    if (checkPermission(Manifest.permission.BLUETOOTH, 101)) {
        // Commands is a dictionary for converting string commands to integers 
        msg.setValue(commands.get(signal));
        gatt.beginReliableWrite();
        gatt.writeCharacteristic(msg);
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source