I have a performance problem.
So I'm writing a chat application and I have a ViewPager
with Fragments in it for each separate chat, the ViewPager
lives in ChatActivity
, and the messages in the Fragments are displayed via a simple ListView
.
Everything is smooth as long as I "minimize" my application. When the app is minimized, and I receive, say just 10 messages during that time, and return back to the activity, there is a noticeable delay (e.g. the standard Android Application restore animation does not play). If I minimize the app again, and restore it instantly, the delay is completely gone (assuming no new messages arrived).
There seems to be no correlation in the performance to the amount of new messages that have arrived: whether there are 10 or 500 new messages, the delay is the same.
I receive messages from a Socket
, pass them to the Chat
object, which simply passes them to the ChatFragment
, which just uses listView.post()
to post them into the ListView
.
My ChatFragment
and ListView
's adapter are pretty trivial so I don't post them here, the messages are stored in an ArrayList
in the Chat
object (the adapter just pulls them from there).. I'm really not doing anything "fancy".
To put it simply, when my Activity
(and the Fragments in it) are paused, and new data is posted to the ListView
, the ListView
(I assume) has to do "more work at once" when the Fragment
is resumed and the ListView
is "refreshed".
This might be a bit vague without code, but perhaps someone can tell me if my principle is at least right (i.e. simply post() the messages to the adapter, regardless if the Activity
and Fragment
are visible to the user?).
If anyone has any ideas what might cause this delay, I'd be very grateful.