0

In my activtiy, I am loading a recyclerview that downloads pictures from the internet.

The only problem is, that the acitvity will only become visible when the loading of the pictures is done. I call the function from within the OnCreate() method. Since this made it obvious, I decided to put the function into OnWindowFocusChanged(), yet still the activity will only start showing when the pictures are loaded. (This is like a 1 second delay, but its a litttle too much.)

Where would I call my InitRecView() method to make sure it will start loading once the activity is already visible to the user?

Thanks

Ian H.
  • 3,840
  • 4
  • 30
  • 60
innomotion media
  • 862
  • 11
  • 30

1 Answers1

0

You are getting this problem because you are loading images on main thread. It may also cause skipping layouts. Here is the solution: Use Handler or Async task for download images, show progress till then and once image is downloaded then notify adapter using adapter.notifydatasetchanged().

note:make sure you write UI related code in runOnUiThread since you cannot handle UI elements in background task.

Pratim P
  • 169
  • 1
  • 5