Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLiteDiskIOException with error code 10: disk I/O error

I moved an SQLite database to an SD card, but sometimes it will throw the following exception:

android.database.sqlite.SQLiteDiskIOException: error code 10: disk I/O error 

Any suggestions on how I can prevent this from happening?

like image 599
yava Avatar asked Aug 10 '11 10:08

yava


1 Answers

Since you are using External Storage, your application must be aware of the External Storage state, which you can get via Environment.getExternalStorageState().

You must only access External Storage when the state is MOUNTED.

If you are trying to open a file (or SQLite DB; it's just a file!) during device startup, you will definitely have problems, because External Storage is not mounted until well into device startup (after Home Screen is displayed).

The way out of this is to register an IntentFilter to be notified of all changes in External Storage state, and behave accordingly.

It's always a good idea to read the documentation! See the Android documentation for details: http://developer.android.com/reference/android/os/Environment.html

Using External Storage for this purpose is dubious, because you cannot control when it becomes unavailable! For example, the user plugs their device into USB on their computer, and selects the "Enable USB Mass Storage" option, so they can access their device's External Storage from their computer. Bad news! Your app will be disconnected from External Storage, and most-likely without the opportunity to do any clean-up IO!

With this state of affairs, you are now left with What To Do with all the data you would be putting into your database, if only it were available.

like image 64
escape-llc Avatar answered Oct 05 '22 11:10

escape-llc