Android MMS: The application analysis of contact management _android

Source: Internet
Author: User

The contact person is important to MMS because each recipient of the conversation is a contact, and when you create a new message, you can enter any information about the contact, such as the number or name, and MMS can send the information to the appropriate person. MMS is used to represent a contact person, it contains contact information, such as the name, number, contact ID, whether it exists in the contact database, and so on, but also provides some ways to get the Contacts object, Contact.get () method to get the contact object. The contact keeps the data synchronized with the Contacts database, and an interface Updatecontact () is used to inform the contact that the information has changed.

inside the contact also has a cache, used to save the most recently used contacts. because the external use of the Contact.get () method to obtain contact is usually passed to a number, and expect to get contact.

The cache inside the contact is created and managed by the Contactcache class. It also has an internal taskstack for managing some runnable. Because each loaded contact from the database is a separate thread, this taskstack is dedicated to managing runnable and, in a stack of ways, to run runnable tasks in a filo order.

There are many overloaded get () methods in Contactcache for getting the contact object, all of which have a Boolean parameter canblock, whether to load the contact as a blocking caller or to load it asynchronously. Another parameter is the number of the contact person. The Get () method invokes the Internalget () method first, Internalget () attempts to obtain the contact from the internal cachemcontacthash, and if it does not exist, creates a new contact with the incoming number. In short, it will definitely return a contact person. Then the action of Updatecontact () Updatecontact () is placed in a runnable thread, and if the caller is blocked, run the runnable immediately to Updatecontact, If it's asynchronous, put the runnable in the Taskstack and run later. Updatecontact will call Getcontactinfo to get the contact information, Getcontactinfo will call Getcontactinfoforself (), Getcontactinfoforphonenumber, Getcontactinfoforemailaddress () to obtain specific contact information. Where if this number is a cell phone contact person itself, to obtain the relevant information about the machine; If the number is an email address or a short number, or a character number, then the number as an email address to query, that is, it as a contact email field matching to query; That is, the number is a phone number, and it matches the contact's phone number field query. Updatecontact after the query completes, the interface Updatelistener.onupdate () is invoked to tell the listener that the contact has been updated. Because the contact is asynchronous during acquisition, the interface is invoked to notify when the update is complete.

The internal cache data structure is a hashmap<string,arraylist<contact>>,key is generated by the internal data of the contact. Invalidatecache does not remove the internal mcontactshash data, but it is identified as stale, when the next get this contact will call Updatecontact () to update the contact.

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.