android - Is it okay to call finish() directly after invoking Provider methods? -
setup: firstactivity opens secondactivity, secondactivity asks user select images, give them titles; when user finished click "save" button invokes method savetodatabase calls bulk insert. desire have user return firstactivity after click "save" button.
this current setup:
private void savetodatabase() { int arraysize = beanlist.size(); contentvalues[] valuesarray = new contentvalues[arraysize]; contentvalues values; string imageuri; string title; int counter = 0; for(bean b : beanlist){ imageuri = b.getimageuri(); title = b.getimagetitle(); values = new contentvalues(); values.put(collectionstable.col_name, nameofcollection); values.put(collectionstable.col_imageuri, imageuri); values.put(collectionstable.col_title, title); values.put(collectionstable.col_seq, counter +1); valuesarray[counter] = values; counter++; } getcontentresolver().bulkinsert(collectionscontentprovider.content_uri, valuesarray); // squash db/provider call? working always? finish(); }
...and working have lingering fear may not work time. question is, calling finish()
directly after getcontentresolver().bulk...
issue? there better way handle i'm trying (save database & return user previous activity in response 1 user event)? thank you. ps: first app, if see code should handled better i'm ears on that, too.
so main question was: okay call finish()
directly after provider method call. , given makovkastar's comments, solution not call finish()
directly after provider method call instead like:
private void savetodatabase() { int arraysize = beanlist.size(); final contentvalues[] valuesarray = new contentvalues[arraysize]; contentvalues values; string imageuri; string title; int counter = 0; for(bean b : beanlist){ imageuri = b.getimageuri(); title = b.getimagetitle(); values = new contentvalues(); values.put(collectionstable.col_name, nameofcollection); values.put(collectionstable.col_imageuri, imageuri); values.put(collectionstable.col_title, title); values.put(collectionstable.col_seq, counter +1); valuesarray[counter] = values; counter++; } asynctask<void, void, void> task = new asynctask<void, void, void>() { @override protected void doinbackground(void... arg0) { getcontentresolver().bulkinsert(collectionscontentprovider.content_uri, valuesarray); return null; } @override protected void onpostexecute(void result) { finish(); } }; task.execute(); }
this works , previous fears allayed. thanks, makovkastar.
Comments
Post a Comment