1

I am new to android development. I came across a project in kotlin where post was used in RecyclerView.

recyclerView?.post { layoutManager?.scrollToPosition(MainActivity.currentPosition) }

Can anyone please explain what is the use of post in the above case? Thanks in advance

Prags
  • 2,457
  • 2
  • 21
  • 38
krai29
  • 153
  • 3
  • 16

1 Answers1

0

It sends a Runnable to the Handler object that is associated with the recyclerView.

If you aren't familiar with Handler, it is one way to execute code on another thread. When you run on a secondary thread, and want to come back to the apps main UI thread, you can use a post method, pass a runnable, and it will run on the main thread.

Note: Handlers can exist on other threads as well.

Daniel B.
  • 2,491
  • 2
  • 12
  • 23