sensorLandscape and handling configuration changes - android

I have a game activity which was previously declared as "landscape" in AndroidManifest.xml.
I experimented with using "sensorLandscape" in order to support the reverse landscape mode, and I expected the activity to be recreated each time I rotate it - like the switch from portrait to landscape.
To my surprise, the activity just rotated without recreation (tested on Nexus 4, stock Android ROM).
The question is - can I count on this behavior? Or am I supposed to add code to handle configuration changes just because I support reverse landscape? It looks like I don't need to do anything, but who knows what devices I might encounter... Writing the state saving code might be really time consuming in my project, that's why I'm concerned whether it's even needed.

Interesting question. Here's what I found here:
Note: When you declare one of the landscape or portrait values, it is considered a hard requirement for the orientation in which the activity runs. As such, the value you declare enables filtering by services such as Google Play so your application is available only to devices that support the orientation required by your activities. For example, if you declare either "landscape", "reverseLandscape", or "sensorLandscape", then your application will be available only to devices that support landscape orientation. However, you should also explicitly declare that your application requires either portrait or landscape orientation with the element. For example, . This is purely a filtering behavior provided by Google Play (and other services that support it) and the platform itself does not control whether your app can be installed when a device supports only certain orientations.
In general - the sensorLandscape is not re-creating the Activity.

Related

Disallow multi-window (split-screen) without setting `android:resizeableActivity` in the manifest

We are an OEM working with an external app developer. The app they have written locks to portrait with android:screenOrientation="portrait" in its manifest. It also disallows resizing with android:resizeableActivity="false".
Our device is designed for use in vehicles and as such operates as a vehicle control head. It does not support portrait mode; any apps that request it are resized to allow landscape display. Because of the aforementioned attributes in the manifest, the app always displays in screen compatibility mode, with the UI squashed in the centre of the screen.
We've tried a number of different solutions. We tried setting the orientation programmatically instead of the in the manifest, but this causes an initial rotation on some handset devices that the app already supports, and which was deemed unacceptable by their QA team. They maintain that the attributes in their manifest mentioned above MUST NOT be removed.
Has anyone been in this situation? Are there any fixes on the application side that we've missed? Would they have to revise their decision to statically disallow resizing?

Is android app by default support both orientation?

I'm not developer. I'm wondering when design an android app, by default, is both orientation portrait and landscape supported?
Only when specifically required, then developer can set it locked to portrait mode only.
The reason I'm asking this, developer request to have such statement mentioned in the spec.
As a analyst, I supposed if not mentioned specifically, then the app just follow device setting.
When device is set to auto rotate, then app rotate as it.

Android - Check if rotation available on homescreen/launcher

I'm currently writing an Wallpaper application for android. I wish to support rotations that's no problem. For a better usability I need to know if the homescreen rotate the screen.
Is there a default that all phones doesn't rotate there homescreen? Currently all phones I have seen didn't rotate. But tablets change the orientation of homescreen. Or there are differences between manufacturers?
I have search for a method (or constant) like boolean supportRotation();
Does anyone have any experience with this problem?
Thanks for help.
I've read that this is not possible, given the fact that any particular user could be using any one of hundreds of launchers available for the home screen.
You could explicitly allow the user the option of enabling the rotation feature, depending on their home screen configuration. i.e - just a simple checkbox in your app.
Alternatively you could extend the app for more screen sizes. Since you are already dealing with different screen widths/heights you could just make this compatible for all screens. Not as trivial though.
You can determine the screen orientation within the app itself but the home screen is a different story altogether.
If someone does have a solution I'd be glad to know, but I don't believe it exists, I've experienced the same problems as you too.
Almost all android device support rotation or say orientation modes.
I suggest you must specify which orientation of your app.
Don't apply the orientation to the application element, instead you should apply the attribute to the activity element, and you must also set configChanges as noted below.
Example:
<activity
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
This is applied in the manifest file at, for example, /platforms/android/AndroidManifest.xml.

App still rotates in landscape mode when device's Screen Orientation setting is off

I set my app to rotate 180 degrees by setting android:screenOrientation="sensorLandscape" on the activities in my manifest. But when the setting for screen orientation in device is turned off, the app is still rotating.
My app needs to rotate 180 degress in landscape mode but should not rotate when screen orientation setting is turned off. How can I solve this?
I believe you should be using landscape and not sensorLandscape. The sensor type attributes don't respect the orientation lock, and will still rotate regardless of that setting.
I couldn't seem to find out for sure whether landscape meant both 90 and 270 degree landscape, but give it a shot -- I believe that's your answer.
I Haven't used this personally but from the doc here I can see
Note: When you declare one of the landscape or portrait values, it is
considered a hard requirement for the orientation in which the
activity runs. As such, the value you declare enables filtering by
services such as Google Play so your application is available only to
devices that support the orientation required by your activities. For
example, if you declare either "landscape", "reverseLandscape", or
"sensorLandscape", then your application will be available only to
devices that support landscape orientation. However, you should also
explicitly declare that your application requires either portrait or
landscape orientation with the element. For example,
. This
is purely a filtering behavior provided by Google Play (and other
services that support it) and the platform itself does not control
whether your app can be installed when a device supports only certain
orientations.
so you can try
<uses-feature android:name="android.hardware.screen.landscape"/>.

Set Android app screen orientation by device

I'm looking to change the screen orientation based on device type. The case is that our development platform is hooked via HMDI to an LCD (and is fixed), and then tested on an actual handset or tablet. I want the development platform to always appear in landscape, and everything else in portrait.
I wrote a little static method that accepts an Activity object and calls it's setScreenOrientation if the device is a certain type. I place the call to this method in the Activitys onCreate, passing itself as the parameter. Alternately, I placed it in the onStart as well. The issue is that it's leading to unpredictable behavior. I suspect the Activity is being restarted by the call to setRequestedOrientation. The API does state that "it is possible for the Activity to be restarted" by calling this method. Sometimes it will change orientation a few times before settling out, sometime it won't, and it always seems to crash the application.
I guess the question becomes: How do I set the orientation for an Activity that hasn't been started yet without using the Manifest?
Any help is appreciated.
Thanks,
Brian
You can't set the orientation dynamically before you actually run.
If you want your orientation to vary, you should use one of the orientation modes: the default one allowing it to vary based on the device preference and how the user rotates the screen, "nosensor" to use the device's preferred orientation without allowing it to changed based on the user rotating the screen, etc.

Categories

Resources