Search code examples
androidandroid-webviewback

android webview onBackPressed


I have webview based app which loads data using both loadDataWithBaseURL (remote urls) and loadUrl calls (from assets). How do I now handle backPress.

ex use case. step 1 - no default page to show set so show static page from assets. Lets call this static page as S1. On S1 we can add pages like bookmarks and set one of them as default like homepage. Lets call home page as H1.

if H1 set using previous step on S1 show H1 using loadDataWithBaseURL (I do some preprocessing).

step 2 - from H1 I use a href to to go to S1. On S1 press back onBackPressed is called but its blank page.

So I would like to get your views on how to handle history when we are using loadDataWithBaseURL, loadUrl (from assets).

Regards,

Miten.


Solution

  • Use Window.history.back() method or Android finish() method