In MMS, eachThreadhas a corresponding contact, butThreadsThe table does not directly save the contact's information (number or name), but instead saves a message calledrecipient_id, there is also a class calledData/recipientidcache.javaspecialize in managing it.
There is a special table in the database to save itcanonical_addresses。 Its purpose is to be able to quickly find information about a contact person in a conversation. Table of DialogsThreadsThere is no direct information to save the contact person, but a column calledRecipient_idsInteger to represent the addressee. And there's another table in the database calledcanonical_addresses, which is used to matchThreadsIn theRecipient_idsAnd number, which has only two columns, one is _id, and the other is its number. Because the conversation does not directly save the contact information, so whenconversationlistWant to display aThread, you need to find it first.RecipientidAnd then according to this recipientid tocanonical_addressesFind the number in the, and then use this number to contact the database to query other information about the contact person. This whole process is quite cumbersome, need to query three times database to get contact information, can not be quickly displayed. So there it is.RecipientidcacheThis class has a hash table inside this class, and the key isThreadOfRecipientid, the value is the number of the contact person. Other classes, such asConversationIn the queryThreadWill not go directly to the querycanonical_addressesTable to get the correspondingRecipientidThe number of the contact person, but directly through theRecipientidcacheTo get.RecipientidcacheFirst of all from their ownCacheTo find the number, if not found to query the database, and add toCacheIn Every time you send a message, you will update the cache action. BecauseRecipientidIsThreadA property in theThreadWhen a table is changed, such as deleting aThreadwill be updated when youRecipientidcache。