Bug 8423 - OnConfiguration not called unless ScreenSize and Orientation flags used together
Summary: OnConfiguration not called unless ScreenSize and Orientation flags used together
Status: RESOLVED UPSTREAM
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.8.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-11-15 08:32 UTC by Wayne Phipps
Modified: 2012-11-15 15:19 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED UPSTREAM

Description Wayne Phipps 2012-11-15 08:32:01 UTC
Description of Problem:
I have found that OnConfiguration is not called unless ConfigChanges.ScreenSize and ConfigChanges.Orientation are used together.

I guess this could also be a problem relating to the auto-generation of the AndroidManifest.xml?

Steps to reproduce the problem:
Use the following code:
namespace RotationTest1
{
	[Activity (Label = "RotationTest1", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
	public class Activity1 : Activity
	{
		static int count, orientation = 0;

		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);
			Console.WriteLine();
			Console.WriteLine( "OnCreate " + ++count);
		}

		public override void OnConfigurationChanged (Android.Content.Res.Configuration newConfig)
		{

			base.OnConfigurationChanged (newConfig);
			Console.WriteLine( "ConfigChanged " + ++orientation );
		}
	}

2. Remeove either ConfigChanges.ScreenSize or ConfigChanges.Orientation and run


Actual Results:
OnCreate gets called unless both flags are present

Expected Results:
OnConfigurationChanged when either flags are present

How often does this happen? 


Additional Information:
Device = Nexus 7
IDE = MonoDevelop v3.0.5
Target API = 16 (Jelly Beann)
Comment 1 Jonathan Pryor 2012-11-15 15:19:20 UTC
This appears to be By Design:

http://developer.android.com/guide/topics/manifest/activity-element.html#config
> "orientation"         The screen orientation has changed — the user has 
>                       rotated the device.
>                       > Note: If your application targets API level 13 or
>                       > higher (as declared by the minSdkVersion and
>                       > targetSdkVersion attributes), then you should also 
>                       > declare the "screenSize" configuration, because it 
>                       > also changes when a device switches between portrait 
>                       > and landscape orientations.

I believe that the "should" in the above note should be "must", given:

http://stackoverflow.com/a/11704022/83444
> In API level 13 or above, the screen size changes when the orientation
> changes, so this still causes the activity to be destroyed and started
> when orientation changes.

Note that that's a Android/Java question noting that when targeting API 13 or later (e.g. API 16), both both orientation and screensize must be provided or the Activity to be recreated.