Android Question onConfigurationChanged....

moster67

Expert
Licensed User
Longtime User
First of all, I have already read the official documentation including disadvantages of using "onConfigurationChanged" and "configChanges attribute" in the manifest and skipping OnCreate.

However, sometimes its usage can be justified, for instance when using VideoView and an orientation change takes place. In this case, using the "configChanges attribute" (
android:configChanges="orientation|screenSize") in the manifest, the playing of the video will not interrupt which makes the user-experience much better. I have tested this successfully using only the "configChanges attribute" in the manifest and it works fine.

However, there may be reasons (for instance for layout-issues) where it would be also useful to intercept the configuration-change and to do that I would need to be able to use "onConfigurationChanged". In java-code it could be:

B4X:
@Override
    public void onConfigurationChanged(Configuration newConfig) {
        if (!AndroidUtil.isHoneycombOrLater())
            //some method - changeSurfaceLayout();
        super.onConfigurationChanged(newConfig);
        //some method - resetHudLayout();
    }

I had a play with the JavaObject library and CreateEvent but couldn't get it right.

Could someone help and show how to implement onConfigurationChanged in B4A?

Thanks.
 

JordiCP

Expert
Licensed User
Longtime User
If i were you i'd use inline java to define the onConfigurationChanged callback.
Have you tried that yet?
That's the way (a-ha)

I use this in my app and works normally
B4X:
#if JAVA
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    BA.Log("CONFIG CHANGED YEAH!!!!!");
    //Your handling
    int a=0;
    processBA.raiseEvent(null, "config_changed"); // servira per posar el flag mHidden=0                                                       
   
    //....
    //setScreenLimits();
  
}
//...
#end if
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Thanks guys - I completely forgot about inline java (silly me)
 
Upvote 0
Top