I display a list of device's contacts. In my Samsung Galaxy S8 with Android version 9, when I scroll the recyclerView for very first time, it is not smooth and lagging a little bit. But then it start to scroll smoothly very well. If I close the app using back button and start the app again, it scrolls smoothly again, but If I destroy instance of app from recent history, and start the app again, it is not smooth and lagging a little bit just at first scroll. ( I have tested in Google Pixel2, and when there is low buttery, I feel the same lag as I explained. )
Here is a recorded screen from the issue in Galaxy s8 : https://drive.google.com/file/d/1szfF1oKEYZK3LIqQHC-MsapRxdJ85bFy/view?usp=sharing
I optimized recyclerView adapter as much as possible, and it seems issue is not related to my Adapter. You can check the source code here : https://github.com/AliRezaeiii/DignityContacts
I have a customized CoordinatorLayout.Behavior to hide/show AppBarLayout as well as bottomBar. I am sure that it is not related to that since when there is not CoordinatorLayout behavior, it shows lagging again as I explained above.
Here is my recyclerView item layout :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">
<include layout="@layout/contact_separator" />
<include layout="@layout/contact_detail" />
<LinearLayout
android:id="@+id/subItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
contact_separator and contact_detail are both ConstaintLayouts.
Here is how I setup recyclerView :
mAdapter = new ContactsAdapter();
binding.recyclerView.setHasFixedSize(true);
binding.recyclerView.setAdapter(mAdapter);
final Observer<Resource<List<Contact>>> contactsObserver = resource -> {
if (resource instanceof Resource.Success) {
mContacts = ((Resource.Success<List<Contact>>) resource).getData();
mAdapter.setItems(mContacts, true);
}
};
What could be the reason of that?