Android mobile guard 8 -- delete call records, android8 --

Source: Internet
Author: User

Android mobile guard 8 -- delete call records, android8 --

1. Pay attention to bugs when writing code:

When deleting the call record, the previous call record is deleted. The phone number intercepted this time is not deleted ??????
Cause: the phone number of the current call record in the database has not been inserted, so the delete operation is performed.

2. bug solution:

Content Provider: provides external database access
Content parser: uses the access Uri provided by the content provider to access the database (add, delete, modify, and query)
Content observer: Observe the changes in the database. Once the data changes, call the corresponding method.

Observe the database insertion through the content observer. Once there is insertion, delete the inserted data.

Public void endCall (String phone ){...... // 6. On the content parser, register the content observer and observe the database through the content observer (Uri determines the database of the table) mContentObserver = new MyContentObserver (new Handler (), phone); getContentResolver (). registerContentObserver (Uri. parse ("content: // call_log/CILS"), true, mContentObserver );}}


Class MyContentObserver extends ContentObserver {private String phone; public MyContentObserver (Handler handler, String phone) {super (handler); this. phone = phone;} // when the specified CALS table in the database changes, the method @ Overridepublic void onChange (boolean selfChange) will be called {// after inserting a piece of data, delete getContentResolver (). delete (Uri. parse ("content: // call_log/CILS"), "number =? ", New String [] {phone}); super. onChange (selfChange );}}



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: 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.