ScreenOrientation without Destroying Activity

reeZZer

Member
Licensed User
Longtime User
Hello,

i'm working on a Chat APP and would like to start with the Landscape mode too.

I'm using the Network Lib and on every Screen Orientation the Connection to the Active socket gets lost and ofc the views get destroyed.

I found an interesting line to add in the Manifest XML:
B4X:
android:configChanges="keyboardHidden|orientation"
which will prevent the Activity to be Destroyed and an Event should be raised when the Screen Orientation change:
B4X:
@Override
public void onConfigurationChanged(Configuration newConfig) {

}

Is there a way to realise this in B4A without an extra Lib? (or if there is one which is the Name?)

Thanks in advance.
 

walterf25

Expert
Licensed User
Longtime User
Screen Orientation without destroying activity

Hello friend, i'm fairly new to Basic4Android, and faced the same issue you're dealing with right now, i now use the StateManager module which has worked very well for me in most of the apps i've worked on, please take a look herehttp://www.b4x.com/forum/basic4android-getting-started-tutorials/9777-statemanager-helps-managing-android-applications-settings-state.html#post54161
Or nother way you can handle this is by using the Sub Activity_Resume and Sub Activity_Pause subs, you can declare global variables and save your information in this variables before switching screen orientation.

Hope i'm making sense, let me know if you have any questions i'll be more than happy to help you out

Walter
 
Upvote 0

reeZZer

Member
Licensed User
Longtime User
Hello,

i can now keep up the Network (Socket) and all other non-Activity based Functions by declaring them on Process_Globals.

My actual Problem now is i'm using a Label with Richstring and ClickableTextView Library which makes the Text Colored and some Text is clickable, if i copy the whole Text and set it on Resume the Color and Clickable Text is gone.

Is there any solution ? i don't think so.

Thanks anyways.
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Did a means to gain access to onConfigurationChanged ever get added to B4A or a library? I tried this on one activity and it is an interesting effect if I could just get an event to know when to resize/move my controls. PhoneSensors is as closes as I've found, but the results from it are hard to process. I'd rather get an event just at the four positions like getRotation returns.
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
It would just be a good option to have my app not be destroyed and recreated on something as simple as a screen rotation. It would be nice to just get an Event when it happens and resize my controls. Destroying works fine for those using the designer, but for those building interfaces by code this would be much easier. Not only is it easier to manage the code, but the interface is much faster when just sizing the controls instead of them being destroyed and recreated all the time. I would much rather have my app only destroyed by the OS.

It would work best to have it just like one of the Activity Events or something. If they don't use it then nothing is changed and I'd guess internally B4A would just pass the event on and the App would get destroyed as usual. Otherwise the developer can process it and pass true back to avoid the app being destroyed. That may not be the correct way it happens and/or it may need reverse logic like if passing it on does nothing then B4A may need to call something that destroys the app and calls Create/Resume again, but whatever needs done to get it shouldn't be that much.

Some of the threads seem to also use it to capture keyboard events to prevent hardware keyboards from crashing the app when they fly out. The threads are a little old and I'd think that would be something big, so either it was fixed already and some code is there that could be easily tweaked to add this or this could be used to fix it too if not.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
I found an interesting line to add in the Manifest XML:
B4X:
android:configChanges="keyboardHidden|orientation"
which will prevent the Activity to be Destroyed and an Event should be raised when the Screen Orientation change:

Google warns against using it:
Note: Using this attribute should be avoided and used only as a last-resort. Please read Handling Runtime Changes for more information about how to properly handle a restart due to a configuration change.
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
Unfortunately that's just what android does.

In Activity create try this

B4X:
If Activity.Width>Activity.Height Then 'landscape
Else 'portrait 
End If

Regards, Ricky
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Unfortunately that's just what android does.

Yes, it does this, but it doesn't only do this. The use of the text in this thread makes it not do this. I already have code handling the rotations. I'm just suggesting we allow both ways of doing it. There are a lot of changes coming...for those not keeping up on news look at the new Samsung Phones- They allow dragging a video window playing a video around the screen that continues to play while you are doing things. They even took it a step further and allow splitting the screen and running multiple applications at the same time. If we keep stuck in the mindset that Android Pauses Activities before starting another how is it then that multiple can run at the same time?

The capabilities are there we just have to use them. On a desktop the OS is called Windows because it creates windows with a frame and a titlebar. If we made an IDE to create windows and only windows just because that is what Windows does then we'd never have full screen applications or applications with custom skins.
 
Upvote 0
Top