Rajesh Mikkilineni Rajesh Mikkilineni - 1 year ago 62
Android Question

Xmpp chat messages are not updating for the 2nd time opening that activity

I am working on a

chat application for android using smack lib.

  1. for chat I am storing all the chat messages in the database.

When ever I get a incoming chat message and and when ever I send a message to friends I am storing in db.


with some ID conversations.

connetions and setconnection is done in login activity where
connection is created .

I don't have a problem is receiving and send the messages.

For 1st time I open ChatActivity that time I load the previous chat messages of whom I am chating with in a

(ListView with CustomAdapter extends BaseAdapter)

When I send a message, I will add the item to arraylist
and adapter.notifyDataSetChanged();
so it is updated to the listview

For incoming messages from this "with-user" I'm chatting with to be updated in the database and I'm getting from the database and I'm updating the list-view.

For the 1st time every thing works fine and well.

But I go back and open this chat activity to chat again, this time few incoming messages are not updating to the UI i,e list-view.

I tried with all the possible things with list-view and adapters

===> when it is not updating if i press on edit-text soft-keyboard pops up and then I close it . Now if I scroll the list at the bottom they are updated.

===> If without opening and closing soft-keyboard try to pull the list means its not updated in the list-view. But if I click on any row I will
then I'll get a error

The content of the adapter has changed but
did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. Make sure your adapter calls notify-data...etc

Can anyone help on this.

Answer Source

The error message clearly tell you not to update UI from background thread. use performOnUiThread Activity instance method to call notifyDatasetChanged()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download