Webpage wrapper

cdsincfl

Member
Licensed User
Longtime User
Hello,

How can I make the WebView persistant during device orientation?

I am trying to create a wrapper that will open a web page and allow the viewer to navigate through the website. I have created this Appsgeyser and App Inventor and they both work well but have their branding on the Android app.

I turned to B4A and have created the basics using the WebView. It navigates to the URL when the app is started and I can navigate through the website as expected. It seemed so simple and easy. BUT, each time the device orientation is changed the WebView reloads the original URL.

Is the any way to make the current URL in the WebView persistent even through device orientation? I have tried using WebViewExtras and StateManager but have been unable to find a solution.

I have searched the Forum and cannot find anything that addresses this except a post suggesting that the orientation be set fixed to either portrait or landscape. This fixes the issue but is not an acceptable solution for my purpose.

I understand the life cycle of the app but is there truly no way to do this in B4A? It appears that it is possible in Android since both of the other solutions work as expected. Does B4A always have to recreate all resources on device orientation change? Is there any way around this for my situation?

Any direction or help will be appreciated. BTW, this is fantastic work and a very usefull tool. Congrats to all involved in this project.

I have uploaded my test files, hope it helps.
 

Attachments

  • WebViewerWrapper.zip
    186.4 KB · Views: 293

cdsincfl

Member
Licensed User
Longtime User
Have you tried to save the current URL in a process global variable? This will allow you to set the URL again when the activity is recreated.
Thanks Erel for the reply.

The Webview still performs a complete reload of the page. It goes blank then reloads page as when the page is originally accessed. I am attempting to get the webpage contents of the Webview remain where the user is viewing it and just resize the view contents to fit the device display.
 
Upvote 0

cdsincfl

Member
Licensed User
Longtime User
Have you tried to save the current URL in a process global variable? This will allow you to set the URL again when the activity is recreated.
I read in the Forum about adding [android:configChanges="orientation"] to the manifest.

I have tried this also and it still seems to reload the webpage as if the app was initially started. This is what I used, maybe there is some error in my syntax:

<code
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"
android:configChanges="orientation"/>)
/code>

Any help is appreciated.
 
Upvote 0

cdsincfl

Member
Licensed User
Longtime User
Thank you Erel, that works great to stop the page reload.

It also stops the view from resizing when the orientation changes. The view stays in the portrait width when changed to landscape orientation. This setting seems to stop the automatic layout change also. I have used the layout scripts but they also seem to not work with this setting. Is it true these also are affected by this setting?

I know I must handle the orientation change in my code but the layout does not respond to setting my webview.width = activity.width or webview.height = activity.height.
 
Upvote 0

cdsincfl

Member
Licensed User
Longtime User
I have accomplished resetting the layout size width and height when the orientaion is changed. I used the Orientation_OrientationChanged to check if the layout size has changed and if so I set the correct size for the current orientation.

Is there a listener for the DeviceLayout or ScreenLayout that I can use? I have been unable to find any reference to it in the forum or guides.

I appreciate all the help on this issue.
 
Upvote 0

abner69

Member
Licensed User
Longtime User
SetActivityAttribute

You should add this line to the manifest editor:
B4X:
SetActivityAttribute(main, android:configChanged, keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize)

@Erel, can this be done in the activity module area for each activity, or does each diferent activity need an entry in the manifest editor?

regards,

...Pablo
 
Upvote 0
Top