Android MMS: Deep Understanding of Dialog list Management _android

Source: Internet
Author: User
Tags hash

Conversation this class mainly represents the data structure of the dialogue, which holds a thread all the relevant information, such as Recipients,threadid, also used to manage thread, such as query thread, delete thread, update thread , manage ThreadID, manage thread contacts, and so on. Because the thread table has more information associated with other tables, such as contacts and the number of messages, some of the information is written directly in the database. Because there is more information on thread, it is more time-consuming to load, so there is a cache inside the conversation to improve the speed of loading thread.

The way to get conversation objects is through the conversation static Method Conversation.get (), this method first from the internal cache to fetch conversation objects, if the cache does not build objects, and load the information from the database into the object.

Because a conversation represents a thread, the implementation data structure of the conversation's internal cache is a hashset, in which each element is a conversation object. It provides several ways to manipulate the cache: Get, put, remove, replace, etc. Each conversation object can be added only once, or there will be exception thrown. But this cache implementation is very not efficient, directly with a hashset<conversation>, so in get and replace, very inconvenient. Better implementation should be a hash table, the key is ThreadID, the value is conversation object, so you can take advantage of the high efficiency of the hash to query and replace operations. This cache implementation is very simple, the Converation.init () method calls Cacheallthreads () to do the work of the cache. When MMS is started and thread changes, Conversation.init () is also invoked to update the cache, such as when thread is deleted. Convresation.init () starts a new thread and calls Cacheallthreads () in the thread to build the cache of conversation, and the method to get conversation is like Conversation.get ( Will first try to get the conversation object from its cache, if not in the cache, create a new conversation, and add to the cache. Cacheallthreads () queries all thread from the database, constructs a new conversation object, adds the total information of the database to the conversation object, and puts it into the cache.

Related Article

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.