Am developing an android app to read contacts(name and number) from phone and save it in SQLite database(somewhat like syncing contacts to my app, not actually). Already I read and saved contacts that were in the phone.
Now I want to add new contacts that were added to the phone after the app was installed. So what am planning to do is to read all contacts from the phone and compare it with already saved contacts in the database. It is done by comparing numbers(by checking whether read number and number in database are same). If a read number from phone is not found in the database, I want to save that number and its particular contact name into database. The following code is to do it.
public int checkContacts(String name, String number) { // name and number are read from phone String query = "select name,number from contacts"; cur = db1.rawQuery(query, null); // cur is object of Cursor while(cur.moveToNext()) { array.add(cur.getString(1)); // array is object of ArrayList<String> if( !(number.equals(array))) { insertContacts(name, number); // function to insert to database count++; // count is used to get the number of contacts saved } } return count; } Am developing this app using Eclipse and an Android Emulator. After executing this code some 20000+ contacts got saved to my database. Actually there were only 11 contacts in my emulator.
Why this much contacts got added to my database and how can I add only newly added contacts to database ?