What is it called ( what term should i google) when flipping/tilting the phone, so that the view rotates when running android?
My (OpenGL) application crashes when I do this, are there some certain steps you should do when handling OpenGL when this occures?
Is there something else I might want to think about?
if you don't set the AndroidManifest.xml 's attributes for activities that handle their own rotations, your activity will be restarted, the GL context will be recreated, and at least, any surfaces and buffers that you were using will be invalid.
in my gles 1.1 application, I have the following in my AndroidManifest.xml, which specifies that my application activity wants to live on through keyboard and orientation configuration changes, and that the application supports any orientation, but doesn't want it to change -because I don't want to deal with reloading textures or redoing the game layout (yet)
<application android:label="#string/app_name"
android:icon="#drawable/icon"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:debuggable="true">
<activity android:name="MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation"
android:screenOrientation="nosensor"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
The problem is like the configuration change that occurs when the screen orientation change occurs. See Configuration Changes. You might want to tell Android that you will handle the orientation change yourself, via the configChanges attribute.
Some good reading: http://android-developers.blogspot.com/2010/09/one-screen-turn-deserves-another.html
You could try searching for "Screen rotation android" or "Screen rotation android OpenGL" since you're trying to do 3D. When the screen rotates the current surface gets destroyed and a new one gets created already accounting for the new screen dimensions.
I'd recommend looking into some sample code just to see the correct way to handle screen rotation, look for "ApiDemos.apk" in Android (it's open sourced by the way), specifically the ones who use GL", all of them handle screen rotation.
Related
I am trying to setRequestOrientation to a portrait but Activity rotates to landscape and set to portrait when auto-rotate enabled.
The Activity will support both landscape and portrait mode.
The problem will happen above Android 7.0.
Try setting the screen orientation to follow the previous set orientation like this
<activity
android:name="com.my.example.MyActivity"
android:screenOrientation="behind" >
</activity>
Set it to behind.
The default android:screenOrientation is unspecified. This means
The default value. The system chooses the orientation. The policy it uses, and therefore the choices made in specific contexts, may differ from device to device.
In some tablets, for example, the default that the system will choose is landscape, so the system may be auto-rotating to landscape as soon as you start the activity, and then flipping from landscape to portrait when you do your setRequestOrientation.
So to prevent the system from behaving this way, you could try choosing the android:screenOrientation for each of those activities in your android manifest like:
<activity
android:name="com.my.example.MyActivity"
android:screenOrientation="locked" >
</activity>
or
<activity
android:name="com.my.example.MyActivity"
android:screenOrientation="behind" >
</activity>
depending on your app requirements. See the Google documentation for more information on these and other options.
Android Studio 3.6.
I want my app to be always in portrait mode. So in my AndroidMainfest.xml:
<activity
android:name=".activity.SplashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I run the app and SplashActivity shows in portrait mode. Nice.
But the editor shows the following error:
Expecting android:screenOrientation="unspecified"
Why?
In your manifest tag (just under xmlns:android="http://schemas.android.com/apk/res/android"), put
xmlns:tools="http://schemas.android.com/tools"
Then inside the application tag, put
tools:ignore="LockedOrientationActivity"
it only affects Android Studio 3.6+
What is the Issue here?
This issue occurs because android framework wants user to control the app orientation himself it is not advised to restrict your app orientation for example if a user wants to use the app in landscape orientation he just flips the device and sensors will do the work but when a developer restrict screen orientation, even when rotation sensor works app will stay in pre-defined state, in a way you are restricting user's device capabilities.
What to do now?
You have two options.,
First is to ignore the error as it won't cause any build failure even I am doing the same and apk/aab generation is as usual
Another Option is to provide Landscape Layouts or to handle the rotation like in some apps which recognize if orientation gets changed they will prompt the user to change the orientation as the app is not supported in such orientation
It may change in future => at present it is not effecting our build process but it might change in future
In Android studio 3.6.0 i guess they want the user to handle the orientation and encourage developer to use ViewModel stuff.
Let me explain screenOrientation in detail
android:screenOrientation="portrait"
will give you error you have to either specify
android:screenOrientation="fullSensor" or android:screenOrientation="unspecified"
fullSensor Means either you have ON the "Rotate off" or not it will change the orientation based on you move the phone
unspecified Means if you have ON the Rotate off then it will stay only in that orientation and if not then it will change the orientation based on you move the phone.
Add following line after android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity"
Then click Alt+Enter
I found 2 way of solving this problem
First,
Android Studio -> Preferences (for Mac) or Settings (for Windows)
-> Search "chrome"
-> Uncheck "Activity is locked to an orientation"
-> Apply and Ok
-> Sync Project with Gradle file
Second,
Select "Run" from the main menu
-> Edit Configurations.
-> Launch options - Launch
-> Select Nothing or Specified Activity
-> Sync Project with Gradle file
tools:ignore="GoogleAppIndexingWarning,LockedOrientationActivity"
I have used the below Procedure. It works perfectly for me. In Android studio 3.6.0 I think they want the user to handle the orientation and encourage the developer to use ViewModel stuff. Use the below Procedure to ignore that.
Firstly Add :
xmlns:android="http://schemas.android.com/apk/res/android"
in the manifest tag.
Secondly, Add
tools:ignore="LockedOrientationActivity"
in application tag. Happy Coding.
I have faced this issue, In my requirement, some of the activity will support both orientations and remains will keep in portrait, In this case, I resolved by the following steps:
Case-1:- To lock Orientation
Step-1:
Please Add following line Application tag in AndroidManifest.xml
tools:ignore="LockedOrientationActivity"
<application
android:name=".activity.MyApplication"
tools:ignore="LockedOrientationActivity">
Step-2: If you want to lock screen orientation either in portrait or landscape
add the following line in the activity tag
android:screenOrientation="portrait" or "landscape"
Case-2:- Suppose if u want to allow orientation in particular activity and have a specific design for landscape
Step-1:
Remove Orientation value in configchanges and remove screen orientation if it exists from activity tag, and my personal suggestion use (LifecycleObserver) in Activity for without losing values while changing orientation.
android:configChanges="orientation"
android:screenOrientation="portrait" or "landscape"
This is the way I resolve this issue, hope it helps, Thanks & Happy Coding.
Try with below code:
if(MainActivity.this.getResources().getConfiguration().orientation== Configuration.ORIENTATION_PORTRAIT){
MainActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
}
Try putting the following in the activity tag
android:configChanges="orientation"
android:screenOrientation="portrait"
I want to change the basic orientation of an android device. Curently its startup orientation is landscape, I need portrait.
I managed to modify the acceleration values so that the axis now point to where I want them to point to.
But the device seems to have its own definition of up and right. Now I have to change this.
Can someone tell me where this can be done? I guess there is a config file out there that I can't identify.
There are millions of hits searching for this problems. Unfortunately they all deal with java programming, not with OS code.
In your manifest file under activity tag that is on which screen you want to apply that orientation.
For portrait
android:screenOrientation="portrait"
For landscape
android:screenOrientation="landscape"
Add this lines of code in Androidmanifest.xml for the orientation
<activity android:name=".SomeActivity"
android:label="#string/app_name"
android:screenOrientation="landscape">
My app has a handful of windows. After each of those windows is created, I have code whose intent is to lock those windows in portrait mode:
var win = Ti.UI.createWindow({ ... });
win.orientationModes = [ Ti.UI.PORTRAIT ];
I still can't believe that there isn't a more universal way of doing this for Android, but that's a gripe for another day. :-) For now, this is mostly working. I'm hoping someone here can help me remove the mostly qualifier.
The app opens with a tab group containing 4 tabs. If I rotate my device as soon as the default active tab is loaded, the layout rotates as well. Oops. In fact, if I go immediately to any of those tabs and rotate my device, the layout rotates. More oops.
However -- and this is the fun part -- if I relaunch the app and jump first to a secondary window, one loaded from one of the tab windows, and rotate my phone, no display rotation. Yay! Now I jump back to any of the tab windows, the ones that were rotating before, they no longer rotate.
Wat?!
That's the pattern I think I'm seeing right now. Anyone seen this before? I'm guessing that it's a tab group thing, but I don't see any orientation accessors in the API. Any guidance would be much appreciated.
Thanks.
You'll want to add this to your tiapp.xml
<android >
<manifest>
<application>
<activity android:name="org.appcelerator.titanium.TiActivity" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation">
</activity>
</application>
</manifest>
</android>
That will lock your entire app into portrait mode
Create a custom AndroidManifest.xml through the help of this
and add this line in Application Blog
<application
android:debuggable="false"
android:icon="#drawable/appicon"
android:label="iVite"
android:name="IviteApplication" >
<activity
android:configChanges="keyboardHidden"
android:name="org.appcelerator.titanium.TiActivity"
android:screenOrientation="portrait"/>
<activity
android:configChanges="keyboardHidden"
android:name="ti.modules.titanium.ui.TiTabActivity"
android:screenOrientation="portrait"/>
<activity
android:name="ti.modules.titanium.ui.android.TiPreferencesActivity"/>
</application>
This is right way to use. Because, In Tabbar Application. We have also need to set Tabbar Activity and its orientation Setting. Like in above code In above Code.
Here, both Activity Orientation is set through AndroidManifest.xml.
TabbarActivity and Window Activity.
Cheers....
If I do not specify a theme in my android manifest, the screen automatically rotates when device changes orientation. But as soon as I specify a theme in the application or activity tags, automatic screen rotation ceases to happen. This is regardless of whether I specify a standard android theme or a custom one.
Automatic rotation happens with this:
<application android:icon="#drawable/icon" android:label="#string/app_name">
...
</application>
But not with this:
<application android:icon="#drawable/icon" android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent">
...
</application>
This is on an Identity Tab and the API target is Android 2.1-update1
Problem is with the device / implementation. Tried it on a phone from a different vendor and it works.
Thanks #source.rar for the emulator clue. Since I had a device I hadn't bothered to check on the emulator.