Eduardo Coelho
Eduardo Coelho

Reputation: 1963

Mono for Android - All activities in Portrait orientation

I have a MonoDroid application and I'd like to force all my Activities to be presented only in Portrait orientation.

I'd though about creating a an Activity base classe such as:

[Activity (ScreenOrientation = ScreenOrientation.Portrait)]         
public abstract class BaseActivity : Activity
{
}

All other activities in my application should then inherit from it (too avoid repetition and have a central place for defining the ScreenOrientation = ScreenOrientation.Portrait).

However, if you look at the ActivityAttribute definition, looks like it does not support inheritance.

[Serializable]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class ActivityAttribute : Attribute { ... }
  1. Do I have to put the Activity (ScreenOrientation = ScreenOrientation.Portrait) in ALL Activities of my application ?
  2. Is it a bad idea to support only Portrait orientation in the Android world ? (I have a Portrait-only iOS application that works really well and does not need to operate on landscape).

Upvotes: 5

Views: 2707

Answers (1)

dmck
dmck

Reputation: 7861

You need to put the attribute on each Activity. If you were creating a native Android application you would need to mark each Activity in the manifest with android:screenOrientation="portrait", using this attribute signals to Mono For Android to do the same.

Unfortunately the Attribute does not inherit as you noticed.

Upvotes: 5

Related Questions