Android short MMS slide asynchronous loading mechanism

Source: Internet
Author: User
It cannot be remembered whether it is after Android4.0 or after 4.1. When browsing information, the MMS slides are no longer displayed along with the information content. Instead, after the information content is displayed, the background thread is enabled to asynchronously load the MMS slides, after the attachment is loaded, the attachment is displayed. Why is it designed like this? It is mainly used to solve the problem of slow display of MMS. In the original design, to display MMS, you must first prepare for loading the information content, recipient, sending time, topic, and type from the database, status Report and other basic content, including a time-consuming operation, that

It cannot be remembered whether it is after Android 4.0 or 4.1. When browsing information, the MMS slides are no longer displayed along with the information content. Instead, after the information content is displayed, the background thread is enabled to asynchronously load the MMS slides, after the attachment is loaded, the attachment is displayed. Why is it designed like this? It is mainly used to solve the problem of slow display of MMS. In the original design, to display MMS, you must first prepare for loading the information content, recipient, sending time, topic, and type from the database, status Report and other basic content, including a time-consuming operation, that is, loading the MMS Slide attachment. Only after all the above work is completed will the MMS be displayed on the interface, the user can browse. This design is very easy to card and sometimes causes ANR (no corresponding application), especially when our carrier requires 20 pages of MMS slides (10 pages by default ), this problem is even more serious, and information is not displayed for a long time, seriously affecting performance. In terms of function design, the user first wants to see the basic information such as the MMS recipient, MMS subject, sending time, and sending status report, and then chooses to view the slides and other multimedia attachments. We can completely lag the loading of slides. Android currently provides such a design.

First, query the database and load information entries based on the current session. Each information entry and each information entry are displayed in MessageListItem. The information content and data are packaged in MessageItem.

MessageListAdapter. java

Public View newView (Context context, Cursor cursor, ViewGroup parent ){
Int boxType = getItemViewType (cursor );
View view = mInflater. inflate (boxType = INCOMING_ITEM_TYPE_SMS |
BoxType = INCOMING_ITEM_TYPE_MMS )?
R. layout. message_list_item_recv: R. layout. message_list_item_send,
Parent, false );
If (boxType = INCOMING_ITEM_TYPE_MMS | boxType = OUTGOING_ITEM_TYPE_MMS ){
// We 've got an mms item, pre-inflate the mms portion of the view
View. findViewById (R. id. mms_layout_view_stub). setVisibility (View. VISIBLE );
}
Return view;
}

This view is MessageLIstItem. MessagelistAdapter then calls the bindView method to load the view. During loading, it mainly calls the bind method of MessageItem. Currently, we are mainly concerned with the loading of MMS content data by MessageItem and the logic processing of asynchronous loading of Slide attachment.

@ Override
Public void bindView (View view, Context context, Cursor cursor ){
If (View instanceof MessageListItem){
String type = cursor. getString (mColumnsMap. mColumnMsgType );
Long msgId = cursor. getLong (mColumnsMap. mColumnMsgId );

MessageItem msgItem = getCachedMessageItem (type, msgId, cursor );
If (msgItem! = Null ){
MessageListItem mli = (MessageListItem) view;
Int position = cursor. getPosition ();
Mli. bind (msgItem, position = cursor. getCount ()-1, position );
Mli. setMsgListItemHandler (mMsgListItemHandler );
}
}
}

Get a MessageItem by using the getCachedMessageItem method based on the information type and msgId.

Public MessageItem getCachedMessageItem (String type, long msgId, Cursor c ){
MessageItem item = mMessageItemCache. get (getKey (type, msgId ));
If (item = null & c! = Null & isCursorValid (c )){
Try {
Item = new MessageItem (mContext, type, c, mColumnsMap, mHighlight, mFullTimestamp, mSentTimestamp );
MMessageItemCache. put (getKey (item. mType, item. mMsgId), item );
} Catch (MmsException e ){
Log. e (TAG, "getCachedMessageItem:", e );
}
}
Return item;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.