SQLiteDatabase attention

public SQLiteDatabase getWritableDatabase ()

Database upgrade may take a long time, you should not call this method from the application main thread, including fromContentProvider.onCreate().

public SQLiteDatabase getReadableDatabase ()

Like getWritableDatabase(), this method may take a long time to return, so you should not call it from the application main thread, including from ContentProvider.onCreate().


2

down vote

It can be called from anywhere, but it should not be called from the UI thread because you don't know how long the process will take (especially with the different file systems in use). Even if you know the database should be small, you don't know about the file system (can it perform more than one job at a time? are there are thousand other jobs waiting in line already?). You can use an AsyncTask or aThread to call getWriteableDatabase.

 

  I'd use an always-wonderful AsyncTask, called from onCreate.

你可能感兴趣的:(SQLiteDatabase attention)