0
我有一個數據庫。因爲我無法檢查設備中歌曲的添加/刪除,我每次啓動應用程序時都會更新我的歌曲表格。因此,我得到了duplicate of what ever already there in database
。這就是爲什麼我的數據庫大小在每次啓動時都在增加。我的問題是how to insert if any new songs are added
和removed the song from database if any old song deleted
。每次啓動應用程序時數據庫大小增加
Cursor cursorSong = this.managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
projection,selection, null, null);
while (cursor.moveToNext()) {
String sdata = cursor.getString(0);
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_PATH, sdata);
mDB.insert(DataHelper.SONG_TABLE, null,initialValues);
}
但只是在數據庫中添加/刪除1首歌曲,我必須將它與數據庫中的1000首歌曲進行比較..這可以解決我的問題,但會增加性能問題 –
爲避免數據庫大小增加,您必須避免冗餘。別無退路。正如我所看到的,您一次又一次地插入所有歌曲。 另一個可怕的想法是太讓你的文件路徑列有主鍵。所以,它會自動避免重複。 :) 接受答案! – Charan
也投了我的問題 –