Insertion of thousands of contact entries using applyBatch is slow

后端 未结 7 2028
我在风中等你
我在风中等你 2020-11-28 23:02

I\'m developing an application where I need to insert lots of Contact entries. At the current time approx 600 contacts with a total of 6000 phone numbers. The biggest contac

7条回答
  •  死守一世寂寞
    2020-11-28 23:23

    I get the basic solution for you, use "yield points" in batch operation.

    The flip side of using batched operations is that a large batch may lock up the database for a long time preventing other applications from accessing data and potentially causing ANRs ("Application Not Responding" dialogs.)

    To avoid such lockups of the database, make sure to insert "yield points" in the batch. A yield point indicates to the content provider that before executing the next operation it can commit the changes that have already been made, yield to other requests, open another transaction and continue processing operations.

    A yield point will not automatically commit the transaction, but only if there is another request waiting on the database. Normally a sync adapter should insert a yield point at the beginning of each raw contact operation sequence in the batch. See withYieldAllowed(boolean).

    I hope it's may be useful for you.

提交回复
热议问题