- // Create a runnable to move to the page.
- val setCurrentPageRunnable = Runnable {
- // Move to the page.
- webViewViewPager2.currentItem = savedTabPosition
- }
-
- // Move to the page after 50 milliseconds, which should be enough time to for the WebView state adapter to populate the restored pages.
- setCurrentPageHandler.postDelayed(setCurrentPageRunnable, 50)
+ // Switch to the saved tab position.
+ // This has to be done twice because, for some reason, if the above step is skipped there is some race condition where nothing happens and the first page is displayed.
+ webViewViewPager2.post { webViewViewPager2.currentItem = savedTabPosition }