So the main question was: is it okay to call finish()
directly after a Provider method call. And given makovkastar's comments, the solution is not to call finish()
directly after the Provider method call but to instead do something 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 and now my previous fears are allayed. Thanks, makovkastar.