now question is how can I run query only and only ...
# android
r
now question is how can I run query only and only when I make sure copy operation get completed
d
Unless you have a multi-threaded application, that's probably not the issue. You might not be copying the database properly.
r
in the second run application works fine
so it means copying db is ok because I check for file if exist not copy
d
And you don't copy it in another thread or IntentService?
r
val outputStream = FileOutputStream(dbDestinationPath) assetManager.open(DB_NAME).use { input -> outputStream.use { output -> input.copyTo(output) } } I use this to copy dont think run in another thread Im quite new in kotlin and android
the only thing I was suspicious was running on two thread but it seems as you mentioned its not multi thread so what can be the issue
d
Where is that code in? An Activity? Fragment? Service? OR the SQLiteOpenHelper?
r
SQLiteOpenHelper
I will call it in onCreate method in helper class
DatabaseOpenHelper.kt
d
Weird, that should be fine.
Unless, you have multiple instances of it?
r
in home fragment I use this
private val Context.database: DatabaseOpenHelper get() = DatabaseOpenHelper.getInstance(applicationContext)
in other freagment I have same code I know its better to put them in a parent class and extend from it but those fragment/activities shouldnt be the problem
d
Comment out line 38 and 45, and see if it works on first run.
r
ok
no same issue
Dominic
d
Oh, then I'm not sure what could be wrong.
r
@Dominaezzz apart from this I have question I have 250K rows is there any solution to make sqlite query faster
I put index on column and use VACUM
but still its not fast enought
rxkotlin or any other approach
I will go through them and learn them just need to know if there is a technology to make a better user experience and dont lag when typing
d
Trying doing the copy in an
init
block instead of
onCreate()
.
Sqlite should be pretty fast with 250k rows.
r
I will run the query when tryping
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { override fun onQueryTextSubmit(s: String): Boolean { updateUI(s) return true } override fun onQueryTextChange(s: String): Boolean { updateUI(s) return true } })
in updateUI() method
d
Use Room with LiveData. That'll take work off the UI thread.
r
hmmm thanks