I’ve used following code snippet for my activity in order to deal with orientation change.
[Activity (Label = "Activity",ConfigurationChanges = ConfigChanges.Orientation
| ConfigChanges.KeyboardHidden)]
and
public override void OnConfigurationChanged(Android.Content.Res.Configuration newConfig)
{
base.OnConfigurationChanged (newConfig);
if (newConfig.Orientation == Android.Content.Res.Orientation.Landscape)
{
Console.WriteLine("landscape");
}
else if (newConfig.Orientation == Android.Content.Res.Orientation.Portrait)
{
Console.WriteLine("portrait");
}
}
I start with Portrait mode, then switch to Landscape mode and again switch back to Portrait mode. So the expected output should be:
landscape
portrait
but Console Output shows
landscape
landscape
portrait
i.e. When switching from Landscape mode to Portrait mode, if and else both gets executed.
I’ve no idea why this is happening.
I’m absolute beginner to Mono for Android, so any help appreciated.
try this its working …
1) declare above
oncreate()2) overide below method:
3) Add below line in manifeast file of activity: