javaandroidlistviewchat

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.

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).


Solution

  • In this project, BluetoothUtilities takes a context and a handler as parameters. The problem was that I was referencing the wrong context when creating an instance of BluetoothUtilities in the ChatActivity class.

    The context of BluetoothUtilities needed to reference the context of ChatActivity:

    bluetoothUtilities = new BluetoothUtilities(context, handler);
    

    When I hovered over "context" (in Android Studio) in the ChatActivity class, I realized it was referencing another context.

    This is correct:

    bluetoothUtilities = new BluetoothUtilities(context, handler);