The current (1.5_r3) ContentResolver API doesn't offer bulk updates,
or a method of wrapping multiple operations into a transaction.  One
way to optimize your code is to allocate a single ContentValues object
outside of the loop, and recycle it during each pass by calling
clear().  (Currently you're allocating a new object for every update,
which can get expensive.)

j

On Sun, Aug 9, 2009 at 9:41 PM, Daniel King<cnk...@gmail.com> wrote:
>
> I made a programe to update phonetic_names of contacts.
>
> Pronunciation p = new Pronunciation(getResources().openRawResource(
>        R.raw.pronunciations));
> Cursor c = getContentResolver()
>        .query(People.CONTENT_URI, null, "NAME != ''",
>                null, People.DEFAULT_SORT_ORDER);
> int idx_name = c.getColumnIndex(People.NAME);
> int idx_id = c.getColumnIndex(People._ID);
> while (c.moveToNext()) {
>    ContentValues v = new ContentValues();
>    v.put(People.PHONETIC_NAME, p
>            .get(c.getString(idx_name)));
>    Uri u = ContentUris.withAppendedId(People.CONTENT_URI,
>            c.getInt(idx_id));
>    getContentResolver().update(u, v, null, null);
> }
>
> It's very slow. I think it can be fast if there is a transaction. But
> I don't know how.
>
> >
>



-- 
Jeff Sharkey
jshar...@android.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to