Question

Trying to set orientation in manifest file, using a string qualifier

android:screenOrientation="@string/orientation"

Works on an 4.0 asus tablet, but fails on both a 2.1 wildfire and 4.1 Galaxy S. The problem is infact linking to a resource, If portrait is typed in it works.

Ive tried changing the qualifiers used in the tablet to test on the phone. This means the exact same code, resources and layouts are used for all devices. So it cant be spelling mistakes or build issues. But it still fails on the phones and not the tablet. This seems to be yet another bug in android.

Gives the error below, nothing in logcat

Installation error: INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION
Please check logcat output for more details.
Launch canceled!

Manifest section

<activity
    android:name=".MainActivity"
        android:screenOrientation="@string/orientation"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

I know I can do it programatically. But theres another issue with the wildfire, not restarting immediately. Instead it waits for views to be setup etc. This doesnt occur in the other devices.

Googled and found a few others using the methods, but they dont seem to have discovered any problems. http://capdroid.wordpress.com/2012/07/21/different-screen-orientation-on-different-screen-size

Thanks

Was it helpful?

Solution

Trying to set orientation in manifest file, using a string qualifier

While it is a string when you type it into your editor, AFAIK it is actually stored as an integer in the system, and therefore the conversion from a string resource is unlikely to be reliable. Frankly, I'm surprised it works on that one tablet -- the device manufacturer may have added support for this to handle one of their own apps.

While you can use string resources in the manifest, they need to be things that will be stored as strings (e.g., android:label).

You might be able to get this to work with an integer resource, looking up the values used for those constants (probably the same as their Java equivalents).

This seems to be yet another bug in android.

To me, this seems to be yet another place where a developer is going beyond the bounds of documented behavior, then wondering why the undocumented behavior does not work.

OTHER TIPS

I had the same issue, and I've solved it using an integer value instead of a string value, and setting orientation in "onCreate" method:

Example:

values/strings.xml

<resources>

    <integer name="orientation">1</integer>
...

values-sw600dp/strings.xml

<resources>
     <integer name="orientation">0</integer>
</resources>

Then, in your onCreate:

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.setRequestedOrientation(getResources().getInteger(R.integer.orientation));

Every orientation has an integer value, see this page for more details: http://developer.android.com/reference/android/R.attr.html#screenOrientation

Read the official developer document to identify the notation form which are indicated by strings, by putting it into a string resource will yield the parse error as shown in the OP's question.

And no, I would not be jumping to conclusions in classifying it as a "bug", to each and to their own, some manufacturers are free to implement their own mechanism to handle it and others stick to the Google way of the source code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top