Why are the received messages not showing up in the UI?

I have had this problem for several days now and cannot find the way to solve it. To learn more about Android development, I started to work on a newbie Bluetooth chat application. When testing the functionality with two physical devices, it is possible to send and receive text messages (as Logcat shows), but the incoming messages are not showing up in the ChatActivity/UI.

Can maybe and please someone give me a hint on how to solve this?

Thanks a lot in advance.

Relevant code fragments:

This method is part of the BluetoothUtilities class, inside an inner class called ConnectedThread. It supposedly should send the incomming Message to the ChatActivity class:

public void run() {
            Log.i(TAG, "BEGIN mConnectedThread");
            byte[] buffer = new byte[1024];
            int bytes;

            while (true) {
                try {
                    bytes = inputStream.read(buffer);
                    //
                    byte[] readBuf = new byte[bytes];
                    System.arraycopy(buffer, 0, readBuf, 0, bytes);
           
                    handler.obtainMessage(ChatActivity.MESSAGE_READ, bytes, -1, readBuf).sendToTarget();
                    String receivedMessage = new String(readBuf, 0, bytes);
                    handleMessageReceived(buffer, bytes);
                  
                    Log.e(TAG, "Received message (BU run): " + receivedMessage);
                } catch (IOException e) {
                    Log.e(TAG, "disconnected", e);
                    connectionLost();
                    connectionLost();
                    BluetoothUtilities.this.start();
                    break;
                }
            }

//This shows up later in the class, just a redundant method that does not send anything to ChatActivity either 
//Yet the log message is showing up in Logcat of the other device, so it sends the message successfully so far

private void handleMessageReceived(byte[] buffer, int bytes) {     
    String message = new String(buffer, 0, bytes);     
    Log.d("BluetoothUtilities", "Message received BU handleMR: " + message);     
    handler.obtainMessage(ChatActivity.MESSAGE_READ, bytes, -1, buffer).sendToTarget(); 
}

And this is the relevant part of the Chat Activity class:

// Handles messages from BluetoothUtilities
private final Handler handler = new Handler(new Handler.Callback() {
    @Override
    public boolean handleMessage(Message msg) {
        switch (msg.what) {
            case MESSAGE_STATE_CHANGED:
                Log.d(TAG, "MESSAGE_STATE_CHANGED: " + msg.arg1);
                switch (msg.arg1) {
                    case BluetoothUtilities.STATE_NONE:
                    case BluetoothUtilities.STATE_LISTEN:
                        setState("Not connected");
                        break;
                    case BluetoothUtilities.STATE_CONNECTING:
                        setState("Connecting...");
                        break;
                    case BluetoothUtilities.STATE_CONNECTED:
                        setState("Connected: " + contactName);
                        break;
                }
                break;
            case MESSAGE_WRITE:
                byte[] writeBuf = (byte[]) msg.obj;
                String writeMessage = new String(writeBuf);
                Log.d(TAG, "MESSAGE_WRITE CA: " + writeMessage);
                chatStorage.saveMessage(contactAddress, "Me: " + writeMessage);
                addMessage("Me 4: " + writeMessage);
                loadMessages();
                break;
            case MESSAGE_READ:
                byte[] readBuf = (byte[]) msg.obj;
                String readMessage = new String(readBuf, 0, msg.arg1);
                Log.d(TAG, "MESSAGE_READ: " + readMessage);
                onMessageReceived(contactName + ": " + readMessage); // Call to handle received message
                chatStorage.saveMessage(contactAddress, contactName + ": " + readMessage);
                addMessage(contactName + ": " + readMessage);
                loadMessages();
                return true;
                //break;
            case MESSAGE_DEVICE_NAME:
                contactName = msg.getData().getString(DEVICE_NAME);
                break;
            case MESSAGE_TOAST:
                Toast.makeText(ChatActivity.this, msg.getData().getString(TOAST), Toast.LENGTH_SHORT).show();
                break;
        }
        return false;
    }
});

// Later in the class:
//Call this method when a new message is received
//This log message never shows up in Logcat

public void onMessageReceived(String message) {
    Log.d(TAG, "Message received in ChatActivity: " + message);
    //messageList.add("Received: " + message);
    addMessage(contactName + "CA: " + message); // This should update the UI, but does not work 
    adapter.notifyDataSetChanged();
}

This is the ChatActivity layout file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.ChatActivity">

    <!-- Header with Back and Menu Buttons -->
    <LinearLayout
        android:id="@+id/header_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="10dp">

        <ImageButton
            android:id="@+id/back_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_back" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Chat"
            android:textStyle="bold"
            android:textSize="20sp"
            android:gravity="center"/>

        <ImageButton
            android:id="@+id/menu_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_menu" />
    </LinearLayout>

    <!-- Chat Messages List -->
    <ListView
        android:id="@+id/chat_list_2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/header_layout"
        android:layout_above="@id/input_layout"
        android:padding="10dp" />

    <!-- Input Layout for Messages -->
    <LinearLayout
        android:id="@+id/input_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:padding="10dp">

        <EditText
            android:id="@+id/message_input"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="Write a message" />

        <Button
            android:id="@+id/send_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Send" />
    </LinearLayout>

</RelativeLayout>

What I tried:

Write several log messages to be sent in different points to know what is failing. So far I only know the messages are being received, but incoming messages are not being added to the ListView.

The sent messages are appearing in the ChatActivity UI (added to the ListView).

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật