Issue
I'm trying to make a music app just to practice with Kotlin and I made a Recyclerview and function that fetches data from external storage.
Now my problem is that when I ever scroll up or down it keeps lagging and I think the reason is that in onBindViewHolder function I create a bitmap from the Uri by using this code
bitmap = MediaStore.Images.Media.getBitmap(contentResolver,album_uri)
And then I set the bitmap
holder.song_image.setImageBitmap(songList[position].image)
I thought maybe if I create all bitmap all in once and place them into the Arraylist before I create the Recyclerview would help to stop the lag and it did but I had another problem that I can't deal with it in the main thread cause it freezes.
I didn't know what to use so I searched on what to use for that and I read about coroutines but I felt it's kinda for multiple threading/tasks with delay and what so ever but I just needed to do one simple task without freezing the UI Thread.
Solution
Try to use image-loading libraries like Glide, Picasso, Coil. They can load images on background threads.
Answered By - Botirali Kozimov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.