https://kotlinlang.org logo
#android
Title
# android
r

Ramin

08/29/2018, 7:56 AM
now question is how can I run query only and only when I make sure copy operation get completed
d

Dominaezzz

08/29/2018, 8:00 AM
Unless you have a multi-threaded application, that's probably not the issue. You might not be copying the database properly.
r

Ramin

08/29/2018, 8:00 AM
in the second run application works fine
so it means copying db is ok because I check for file if exist not copy
d

Dominaezzz

08/29/2018, 8:01 AM
And you don't copy it in another thread or IntentService?
r

Ramin

08/29/2018, 8:02 AM
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

Dominaezzz

08/29/2018, 8:06 AM
Where is that code in? An Activity? Fragment? Service? OR the SQLiteOpenHelper?
r

Ramin

08/29/2018, 8:06 AM
SQLiteOpenHelper
I will call it in onCreate method in helper class
DatabaseOpenHelper.kt
d

Dominaezzz

08/29/2018, 8:09 AM
Weird, that should be fine.
Unless, you have multiple instances of it?
r

Ramin

08/29/2018, 8:10 AM
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

Dominaezzz

08/29/2018, 8:16 AM
Comment out line 38 and 45, and see if it works on first run.
r

Ramin

08/29/2018, 8:18 AM
ok
no same issue
Dominic
d

Dominaezzz

08/29/2018, 8:39 AM
Oh, then I'm not sure what could be wrong.
r

Ramin

08/29/2018, 8:40 AM
@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

Dominaezzz

08/29/2018, 8:42 AM
Trying doing the copy in an
init
block instead of
onCreate()
.
Sqlite should be pretty fast with 250k rows.
r

Ramin

08/29/2018, 8:44 AM
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

Dominaezzz

08/29/2018, 8:44 AM
Use Room with LiveData. That'll take work off the UI thread.
r

Ramin

08/29/2018, 8:44 AM
hmmm thanks
7 Views