0

I have saved local contacts into the database and that database has 2000 rows. I am using the select query to select all contacts but it takes 6 to 8 secs to get a list

@Query("SELECT * FROM Contacts")
fun getLiveLocalContactList(): LiveData<List<LocalContactsUserEntity>>

Here is Entity

@Entity(tableName = "Contacts")
data class LocalContactsUserEntity(
    @PrimaryKey(autoGenerate = false)
    val mobileNumber: String,
    var name: String
){
    override fun toString(): String {
        return Gson().toJson(this)
    }
}

Is there any solution or am I doing something wrong?

Update For This Question

I have checked That Database Returns Data As Soon as But It is RecyclerView that takes time to load data. How to set huge dataset to RecyclerView Like ContactList in our app.

Gulab Sagevadiya
  • 872
  • 1
  • 8
  • 20
  • try to read this question: https://stackoverflow.com/questions/67575425/android-why-is-room-so-slow – shrimpcolo Sep 29 '21 at 06:11
  • That question is not relevant to my situation. I am just selecting all rows of the table no other logic is needed. it works fine if rows are less than ~400 – Gulab Sagevadiya Sep 30 '21 at 07:10

2 Answers2

0

Instead of Select *, try to add the needed column only. E.g.:

@Query("SELECT id,name,address FROM Contacts")
Yun
  • 3,056
  • 6
  • 9
  • 28
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 29 '21 at 10:00
  • There is only two columns in the table and I need both columns – Gulab Sagevadiya Sep 30 '21 at 07:05
0

So Finally,

I have found the actual reason behind this delay.

I am doing wrong in XML part.

I have added RecyclerView in NestedScrollView So it is taking time to set data to RecyclerView.

Gulab Sagevadiya
  • 872
  • 1
  • 8
  • 20