Android Question Does this method for restarting a B4XPages App with a different orientation work in Android 8+? It works in Android 7.0.

William Lancee

Well-Known Member
Licensed User
Longtime User
I have been experimenting with this. The idea is that although B4XPages is committed to an orientation, this orientation can be
determined at run time, as long as the commitment occurs before B4XPagesManager is Initialized.

If a timer finds that (by using the sensors) the orientation has changed, the App can be stopped and restarted with a new orientation.
The effect is as if the app has paused and resumed. Of course the state of the App must be preserved in an external file.

I have an old Tab S2, so I am stuck with Android 7.0. Can anyone test this with a newer model? It would be nice if it works.

The following is the modified Main Module that implements this idea.

The method for sensing orientation change is extracted from @emexes:
https://www.b4x.com/android/forum/t...-with-portrait-orientation.106872/post-669094

P.S. Ignore log message about orientation.

Edit. I have removed the code that was posted here that caused errors in Android 12. See this corrected code snippet and project .zip.

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

William Lancee

Well-Known Member
Licensed User
Longtime User
Tested and verified on Android 11.
I have added a 'saving App state' procedure.
I will post this extended code as a Android Code Snippet, tagged with [B4XPages]

I have not received any response to this post, which is surprising, given the number of wishes for accommodating
both orientations while still using B4XPages. I am missing something? Just curious.

Is it that @Erel warns not making changes to the "Main" module in the B4XPages template?
I do like to pushing the envelope.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
I just get this error, Android 12...

1638306486774.png


1638306542739.png
 
Last edited:
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Thank you for testing and your feedback.

I ran it with Release (obfuscated) on Android 11 and there were no problems.
Can you post your Manifest file? I'll take a look at what makes 12 different from 11.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Thank you for testing and your feedback.

I ran it with Release (obfuscated) on Android 11 and there were no problems.
Can you post your Manifest file? I'll take a look at what makes 12 different from 11.
My manifest is default, I just created a new blank B4XPages project and copied your code over the original code in the Main Module, oh yes and I selected the Phone library, nothing else..
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Great, thank you again for contributing your time and expertise.

The Phone library is used for setting the orientation dynamically.
Also for using the PhoneSensors.

It won't work here without it (I tried it thinking that maybe these had been incorporated in the core).
But no, so it is a mystery why it would work for you.

Note, the problem with Android 12 probably was caused by me not disabling the timer properly in the code I had in #1.
And probably because your device is much faster than mine.
 
Last edited:
Upvote 0
Top