Gentlemen, who can clarify the question? In my application I use CursorLoader in conjunction with LoaderManager. I do this solely to obtain data from the database. And I was puzzled by the question of how to ensure the thread-safety of this bundle. Everything is clear with loadermanager, but not so with cursorloader.
Conducted an experiment, in the method that performs data retrieval from the database after db.query, but before the return cursor made a delay of one second, and in activity I call the loadermanager two times in a row. The application worked fine, nothing crashed and the second request returned as an answer. But at the same time I have never used sinchronized. As I understand it, when using SQLiteDatabase everything will be fine. it is thread safe and both requests execute sequentially. It seems that everything is clear, but nothing is clear. How does SQLiteDatabase provide thread safety? Here is the code that implements the data request from the database.
public Cursor getEmployees() { SQLiteDatabase db = getReadableDatabase(); String sqlTables = "Test"; String SELECTION_DB = COLUMN_NAME_STATION + " LIKE " + "'" + searchName + "%'"; Cursor cursor = db.query(sqlTables, null, SELECTION_DB, null, null, null, null); try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } cursor.moveToFirst(); return cursor; } Code that is written in a class inherited from CursorLoader
protected Cursor onLoadInBackground() { DbOfStationsSearch db = new DbOfStationsSearch(getContext(), bundle.getString("upd")); Cursor cursor = db.getEmployees(); return cursor; } The activity says the following
getSupportLoaderManager().restartLoader(0, bundle, MainActivity.this); getSupportLoaderManager().restartLoader(0, bundle, MainActivity.this);
SQLiteDatabasedoes not provide thread safety. CallingCursorLoader(which is inherited fromAsyncTaskLoader) executes queries asynchronously. - tim_taller