Android Mms topic: Contact Management

Source: Internet
Author: User

The contact is very important to MMS, because the recipient of each conversation is a contact. When creating information, you can enter any information of the contact, such as the number or name, MMS can send the information to the corresponding person. The class contact in MMS is used to represent a contact. It contains the contact information, such as the name, number, contact ID, and whether the contact exists in the contact database, at the same time, the contact also provides some methods to obtain the contact object. get () method to get the contact object. The contact operation keeps data synchronized with the contact database. An updatecontact () interface is used to notify the contact that the contact information has changed.

The contact also has a cache to save the recently used contacts. This is because when the contact. Get () method is used to obtain the contact, only one number is sent to the external user and the contact is expected to be obtained.

The internal cache of the contact is created and managed by the contactcache class. It also has a taskstack to manage some runnable instances. Since each loaded contact from the database is a separate thread, this taskstack is specifically used to manage runnable and to run runnable tasks in the stack mode, that is, in the Filo sequence mode.

Contactcache has many overloaded get () methods used to obtain contact objects. Each of them has a Boolean parameter canblock, this indicates whether to block the caller to load the contact or asynchronously. Another parameter is the contact number. The get () method first calls the internalget () method. internalget () first tries to obtain the contact from the internal cachemcontacthash. If it does not exist, create a new contact with the incoming number, in short, it will definitely return a contact. The updatecontact () action will be performed later. updatecontact () is placed in a runnable thread. If the caller is blocked, run the runnable to updatecontact immediately, in asynchronous mode, place the runnable in taskstack and run it later. Updatecontact calls getcontactinfo to obtain the contact information. getcontactinfo calls getcontactinfoforself (), getcontactinfoforphonenumber, and getcontactinfoforemailaddress () to obtain the specific contact information. If the phone number is the mobile phone contact itself, it will obtain the relevant information of the local machine; if the number is an email address, a short number, or a character number, in this case, the number is queried as an email address, that is, it is matched as the email field of the contact. In other cases, the number is a phone number, match it with the contact's phone number field for query. After the query is complete, updatecontact calls the updatelistener. onupdate () interface to notify the listener that the contact has been updated. Because the contacts are obtained asynchronously, the interface will be called for notification after the update is complete.

The data structure of the Internal cache is a hashmap <string, arraylist <contact>. The key is generated based on the internal data of the contact. Invalidatecache does not remove the internal data of mcontactshash, but marks it as stale. When you get this contact next time, it will call updatecontact () to update this 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.