Android Question How to save Bluethooth connection state during a screen rotation

mscientist33

Active Member
Licensed User
I have an B4Xpages app the starts up by letting the user choose and connect to a serial Bluetooth device. Once it is connected the app goes to the "main" part of the app. If the user rotates the device, I would like a different layout to be loaded but not have the user to have to go through choosing the bluetooth connection process all over again. Is this possible?
 

William Lancee

Well-Known Member
Licensed User
Longtime User
B4XPages requires the commitment to an orientation, but depending on the details of what you're trying to do it is possible to accommodate
some form of multi-orientation, for example to show a video in full-screen, or to conform the orientation to how the device is held initially.
Since B4Xpages are not paused, connections to Bluetooth should be preserved.

Please explain more.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Having said that, you can restart an B4XPages App with a different orientation. (This removes one key benefit of B4XPages, but if you need it..)

https://www.b4x.com/android/forum/t...reen-orientation-while-using-b4xpages.136476/

You have to save all critical info to an file and restore it. In your case, also save the Mac address and then you can reconnect to the Bluetooth device,
without additional user interaction.
 
Upvote 0

mscientist33

Active Member
Licensed User
Bottom line is you can't just unload a portrait layout and load the landscape layout without shutting down and restarting the whole activity (app)?
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
The design consideration behind B4XPages is that it simplifies the activity cycle of Android by eliminating Pause and Resume.
This helps in making the App cross-platform (Desktop, Android, iOS), but it also means a commitment to a given orientation.
(As I mentioned, you can detect first how the user is holding the device and then make the orientation commitment before starting
B4XPages)

You can have one B4xPages Activity plus one or more non-B4XPages Activities, which can be unspecified orientation.
For example, one can do all the work in a B4XPages App based on how the user held the device when starting the App,
and then start another non-B4XPages Activity in a different orientation (for example to show a video in landscape).
You can access Globals in the first Activity (which is still active - not paused), and return to that Activity when finished with
the non-B4XPages Activity.

For each non-B4Xpages Activity, you'll have to handle the Activity cycle yourself with Pause and Resume subs.

With some planning, the exit and restart operation in the link in post #3 can occur seamlessly to the user.

If none of these approaches work in your situation, just revert back to a traditional B4A App. This is not a limitation of B4A.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…