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 );}}