WebView Reloading Page on Activity_Create

cbanks

Active Member
Licensed User
Longtime User
I want to allow my users to rotate their device when using my app. When my app is run it loads a web page in a webview. The user can navigate on the site in the webview. When the user rotates their device it reloads the initial site listed in my Activity_Create section. I don't want it to do that. I want it to still show the page they're currently browsing. How do I do that? Thanks.
 

warwound

Expert
Licensed User
Longtime User
Hi.

You can save the last loaded URL as a process global and reload it on orientation change:

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim LoadedUrl As String
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   WebView1.Initialize("WebView1")
   Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
   If FirstTime Then
      LoadedUrl="http://www.google.com/"
   End If
End Sub

Sub Activity_Resume
   WebView1.LoadUrl(LoadedUrl)
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub WebView1_PageFinished (Url As String)
   LoadedUrl=Url
End Sub

Martin.
 
Upvote 0
Top