Thursday 15 July 2010

Android - contentResolver.notifyChange() slowing performance -



Android - contentResolver.notifyChange() slowing performance -

i have mycontentprovider class overrides bulkinsert(). within method, utilize sqlite transaction insert 4,000 rows database, takes 25 seconds on samsung galaxy s4 device.

however, when remove line bulkinsert() method...

getcontext().getcontentresolver().notifychange(insertedid, null);

...the total insertion time drops 1 or 2 seconds.

so, there improve way phone call notifychange()?

i have tried calling in thread, this...

new thread(new runnable() { public void run() { getcontext().getcontentresolver().notifychange(insertedid, null); } }).start();

...but it's still slow and, reason, results in outofmemoryerror.

for completeness, here bulkinsert() method...

@override public int bulkinsert(uri uri, contentvalues[] valuesarray) { /* * open read / write database back upwards transaction. */ sqlitedatabase db = dbhelper.getwritabledatabase(); string tablename; switch (urimatcher.match(uri)) { case brands_search: tablename = brand_names_table; break; case products_search: tablename = products_table; break; case parent_companies_search: tablename = parent_companies_table; break; case products_data_search: tablename = products_data_table; break; default: //break; throw new illegalargumentexception("unsupported uri: " + uri); } /* * begin transaction */ db.begintransaction(); int numsuccessfulinsertions = 0; seek { (int = 0; < valuesarray.length; i++) { /* * insert values table */ long rowid = db.insert(tablename, null, valuesarray[i]); if (rowid > -1) { /* * increment numsuccessfulinsertions */ numsuccessfulinsertions++; /* * build uri of newly inserted row. */ uri insertedid = contenturis.withappendedid(uri, rowid); /* * notify observers of alter in info set. */ getcontext().getcontentresolver().notifychange(insertedid, null); } else { /* * don't give (as not insert attempts need succeed) */ //throw new exception("could not insert row"); } } /* * homecoming number of successful insertions */ homecoming numsuccessfulinsertions; } catch(exception e) { log.e(log_tag, "bulkinsert exception", e); /* * homecoming number of successful insertions */ homecoming numsuccessfulinsertions; } { /* * (or all) insertion attempts succeeded */ db.settransactionsuccessful(); /* * end transaction */ db.endtransaction(); } }

notify 1 time mass operation, not 1 time each record inserted. move phone call notifychange such follows loop.

android performance sqlite android-contentprovider android-contentresolver

No comments:

Post a Comment