android:configChanges="keyboardHidden|orientation" Issue Android - android

Am using android:configChanges="keyboardHidden|orientation"for switching between portrait and landscape modes. But when user opens softkeyboard in portrait and changes to landscape keyboard should hide or dissappera but its not happening with that.

If you are intercepting orientation without overriding public void onConfigurationChanged(Configuration newConfig) in your Activity it is normal that the keyboard remains open.
You can either
override this method to reset the display
or avoid intercepting orientation to let the Activity restart (in which case your Activity will be reinitialized and onCreate() will be called again)

I'm not sure in it but I think that you need to write keyboardHidden|orientation|portrait (or landscape).

Related

playing video fullscreen mode in webview fragment android

I have untypical problem. I have fragment with webview and I need to play video in fullscreen. I have no problems with it. But when screen orientation changes - fragment recreated. But I need to continue playing video in fullscreen.
I can't use android:configChanges="orientation|screensize" in AndroidManifest to MainActivity, because MainActivity has two different layout for lanscape and portrait mode.
you can programatically force the screen orientation to be landscape on your fragment, so if the user rotates it do not change(you said you want the video to be fullscreen only so no reason to change a thing when it rotates), and when your activity is open but the fragment not the override on onConfigurationChanged will not be called.
So simply add this on your fragment:
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
It should works... if for any reason doesn't, try to use the same logic on onAttach/onDetach or to check the config change of the activity (if the fragment is open lock the orientation), but I think the code above should solve your problem ;]

Android: How to handle the event of Portrait to Reverse Portrait and Landscape to Reverse Landscape

When the screen orientation changed between (Reverse) Landscape and (Reverse) Portrait, the onCreate method of Activity would always be called. But when the screen orientation changed only between Landscape and Reverse Landscape or between Portrait and Reverse Portrait, the onCreate method even onResume method of Activity would not be called!
How to detect the event about reversing screen orientation?
If I use
android:configChanges="orientation|screenSize"
and
public void onConfigurationChanged(Configuration newConfig)
No mater how I change the screen orientation, the onCreate method and onResume method of Activity would not be called, so that the views' positions on Activity are very weird. So, I prefer the solution about "how to detect the reversing screen orientation event" not to use configChanges.
Does anyone know how to solve it?
You can try this method screenOrientationDidReverse:. when device only reverse the orientation, this method will be called. so... override the method!

How to lock screen orientation when anctivity isn't recreated

I have an activity used to display a video (VideoView).
By default the user can change screen orientation to see the video.
I avoid destroying/recreating the activity upon orientation changes because of latency issue.
The rotation is painless without any sound break.
android:configChanges="keyboardHidden|orientation|screenSize"
What I want to do now is add a button that will force the activity to remain on current orientation.
The problem is that because the activity isn't recreated after the rotation, I don't know which method to override to avoid the rotation to happen.
Overriding onConfigurationChanged is useless because the rotation already happened.
Use setRequestedOrientation().
E.g. to lock the orientation to portrait, call:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
In your activity.

Force Android orientation to landscape

As the title suggests, I am having trouble locking the orientation.
I am using the below code:
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
This is working ok as far as it loads in landscape and when I rotate the mobile, it stays in landscape.
The problem however, is when the power button is pressed to lock the phone, upon unlocking the app is now forced portrait.
Is there a way to capture the unlock event and force it to goto landscape again or any other method?
Thanks in advance.
Just fixed it myself, if anyone else is experiencing the same issue try the following:
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
Set this in the onCreate() method, as well as in the onResume(), you can also set it in the onStop() as well:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Set initial screen orientation

I am making an app where the first screen I want to view is Portrait. I then go to the next activity which is set in landscape.
The problem i'm facing is that if I return to the first screen it will be set as landscape, evidently inheriting the orientation from the previous screen.
Is there a possible way to set the initial screen orientation as portrait which is set but the user can then go ahead and change it to landscape when they want?
Thanks
EDIT: SOLVED
Thank you for your suggestions. I've overcome the issue. It's slightly difficult to explain but will try my up most.
So my first activity has a feature whereby if the phone is turned to landscape it will show an image, full screen. And again, if the phone was portrait, the portrait view, where I have a list view.
The second activity loads an editing page to let me change that image.
So now if i press back on the editor activity. The first activity would load into a list view in LANDSCAPE. which is NOT what I want.
therefore in order to get around this. I have firstly disabled the back button when the first activity is landscape so the user can not remove himself from the view without turning the phone to landscape.
I then moved the code:
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
//Show landscape picture
}
}
to the top of my class before the onCreate method.
This has solved my issue so that now, if I was to go back to my first activity whilst in landscape the only thing that would show is the landscape view.
I hope that was clear enough for all to understand :)
Again thanks for the help!
you can set the screen orientation programmatically in the onCreate()- method:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
just right before the call of super.onCreate();.
I hope, I could help you.
Best regards,
G_J
You can change the orientation of individual activities using this in the manifest file of your application within each of your activity's tags:
android:configChanges="orientation"
with either
android:screenOrientation="portrait"
OR
android:screenOrientation="landscape"
as per your needs
you can set the screen orientation programmatically in the onCreate() method:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
just right after the call of super.onCreate();.
OR
You can also specify the orientation in the Manifest file like this
<activity android:name="com.example.project.activity"
android:screenOrientation="portrait"/>
Thank you for your suggestions. I've overcome the issue. It's slightly difficult to explain but will try my up most.
So my first activity has a feature whereby if the phone is turned to landscape it will show an image, full screen. And again, if the phone was portrait, the portrait view, where I have a list view.
The second activity loads an editing page to let me change that image.
So now if i press back on the editor activity. The first activity would load into a list view in LANDSCAPE. which is NOT what I want.
therefore in order to get around this. I have firstly disabled the back button when the first activity is landscape so the user can not remove himself from the view without turning the phone to landscape.
I then moved the code:
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
//Show landscape picture
}
}
to the top of my class before the onCreate method.
This has solved my issue so that now, if I was to go back to my first activity whilst in landscape the only thing that would show is the landscape view.
I hope that was clear enough for all to understand
Again thanks for the help!

Categories

Resources