It's possible to read data when database is open through DatabaseHelper and there is some process that is already writting to it? My minimum API for application is 7.
2 Answers
Basically writing or reading will be taking just micro-seconds. You don't have to worry about doing concurrent tasks because Android is an Operating System and it has well defined processes to handle these type situations.
If you are providing an explicit lock on the database it wouldn't effect select query. Yes! If you are trying to write while another write operation is going then you will have problem. Select queries doesn't create any problem.
8 Comments
Papaja
Yes maybe this operations takes micro-seconds but i update my application with internet data and while is updating db is still open. And when i want to access data from database in this occasion this read process is waiting for process there is writing to DB and after complete then can read data.
NewUser
@Papaja: If I were you I would provide something like a sync button somewhere. Till sync is finished I would show a loading bar to make sure that user doesn't do any task while updating.
Papaja
Yes, actually i do it in my application :-) Let me explain situation. My application draws graphs from data which are saved in database. In the screen there is a button for manual sync and for draw graphs in new activity. So when user click on sync and progress bar is spinning and then user click on draw graph he have to wait on finish downloading data because database is open for write. But there is any way to read data from this database? Thank you
NewUser
When you are showing a progress bar then how come a user can click a button?
Papaja
<ProgressBar android:id="@+id/titlebarProgress" style="?android:attr/progressBarStyleSmall" android:layout_alignParentRight="true" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_centerInParent="true" android:layout_marginRight="17dp" android:visibility="gone" />
|
Try Closing the database object
And then Re initiating it.
db = this.getReadableDatabase();
//DB Commanad
db.close();
db = this.getWritableDatabase();
//DB Started for another command
db.close();
1 Comment
Papaja
Yes but i wanna still writing in synchronization process and only read data to some execution.