1

Part of my app is opening the browser in app and sending the user to a dedicated webpage (lets call it "FirstPage"). There the user can navigate throw the web pages. That works great, but when the user is in the webpages and the app gets interrupted (by incoming call or pressing the hold button) the browser state is not saved and when the user is coming back to the app, the browser automaticly opens the "FirstPage" and not the last seen page.

How can I save the state of the browser so the last seen page will appear after interruption?

Thank you very much!

yoav
  • 23
  • 3

1 Answers1

0

If the URL is being loaded in the Android native browser, then I don't think it's possible to collect it's last URL and scroll position. That would likely invade the users privacy anyway, since the user could browse around the web, visit a porn site for example, and then you would have stored that URL on their next load.

If however you're using a WebView (docs) you can since it's encapsulated within your app. Functions like computeVerticalScrollOffset() and getURL() would collect that information.

You can store the data in Android Shared Preferences.

If you need to store this information and be ready for the app to end at any moment, you could try storing it on Activity.onDestroy(), Activity.onPause() and Activity.onStop(). I'm not sure how much control you will have to store preferences during app closure/pause/stop, but if you're unable to I suggest you store it whenever a change in scroll position or URL is detected.

Check this answer for tips on how to listen to WebView changes.

Finally, once you are storing the data, you simply need to use the stored preferences upon WebView re-initialisation.

Community
  • 1
  • 1
1owk3y
  • 1,115
  • 1
  • 15
  • 30