Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).
like image 272
Eduardo Coelho Avatar asked Apr 11 '13 19:04

Eduardo Coelho


1 Answers

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.

like image 164
dmck Avatar answered Oct 29 '22 17:10

dmck