code: private void prepareMessages(final List<MessageCenterListItem> originalItems) {
  		assertMainThread();
  
  		listItems.clear();
  		unsentMessagesCount = 0;
  		// Loop through each message item retrieved from database
  		for (MessageCenterListItem item : originalItems) {
  			if (item instanceof ApptentiveMessage) {
  				ApptentiveMessage apptentiveMessage = (ApptentiveMessage) item;
  				Double createdAt = apptentiveMessage.getCreatedAt();
  				if (apptentiveMessage.isOutgoingMessage() && createdAt == null) {
  					unsentMessagesCount++;
  				}
  
  				/*
  				 * Find proper location to insert into the listItems list of the listview.
  				 */
  				ListIterator<MessageCenterListItem> listIterator = listItems.listIterator();
  				ApptentiveMessage next = null;
  				while (listIterator.hasNext()) {
  					next = (ApptentiveMessage) listIterator.next();
  					Double nextCreatedAt = next.getCreatedAt();
  					// For unsent and dropped message, move the iterator to the end, and append there
  					if (createdAt == null || createdAt <= Double.MIN_VALUE) {
  						continue;
  					}
  					// next message has not received by server or received, but has a later created_at time
  					if (nextCreatedAt == null || nextCreatedAt > createdAt) {
  						break;
  					}
  				}
  
  				if (next == null || next.getCreatedAt() == null || createdAt == null || next.getCreatedAt() <= createdAt ||
  					createdAt <= Double.MIN_VALUE) {
  					listIterator.add(item);
  				} else {
  					// Add in front of the message that has later created_at time
  					listIterator.set(item);
  					listIterator.add(next);
  				}
  			}
  		}
  		messagingActionHandler.sendEmptyMessage(MSG_ADD_GREETING);
  	}
docs: /*
  Messages returned from the database was sorted on KEY_ID, which was generated by server
  with seconds resolution. If messages were received by server within a second, messages may be out of order
  This method uses insertion sort to re-sort the messages retrieved from the database