アプリで UserDictionary に複数 (2k) の単語を追加したいと考えています。
ContentResolver().insert/bulk insert... を試しました。
// array of words
String[] words = getResources().getStringArray(R.array.word_array);
Long start,end = null;
start = System.currentTimeMillis();
int len = words.length;
ContentValues[] mValueArray = new ContentValues[len];
ContentValues mNewValues = new ContentValues();
mNewValues.put(UserDictionary.Words.APP_ID, "com.my.example");
mNewValues.put(UserDictionary.Words.LOCALE, "en");
mNewValues.put(UserDictionary.Words.FREQUENCY, "100");
for (int i = 0; i < len; ++i) {
mNewValues.put(UserDictionary.Words.WORD, words[i]);
mValueArray[i] = mNewValues;
}
getContentResolver().bulkInsert(
UserDictionary.Words.CONTENT_URI, // the user dictionary content URI
mValueArray // the values to insert
);
end = System.currentTimeMillis();
Toast toast = Toast.makeText(this, "Time for " + Integer.toString(len-1)+" words: " + Long.toString((end-start)) + "ms", 50);
toast.show();
私の電話では、100 のバッチで一括挿入すると、1 単語あたり約 100 ミリ秒かかります。2k 単語を挿入するには 3 分以上かかります。
単語を挿入するためのより高速な方法や実行可能な最適化を知っている人はいますか?
副次的な質問: UserDictionary のサイズに上限はありますか、それとも電話に依存しますか?
どんな助けでも大歓迎
マイケルスター