On Mar 14, 2012, at 10:03 PM, wanting wrote:
> I have tried setting ActivityAttribute.ConfigurationChanges, and override it.
> But when the screen is reoriented, OnCreate method is called, and
> onConfigurationChanged is never called.
I'm unable to reproduce this:
[Activity (Label = "Scratch.Jni",
MainLauncher = true,
ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation)]
public class Activity1 : Activity
{
int count = 1;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
Console.WriteLine("OnCreate");
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button>
(Resource.Id.myButton);
button.Click += delegate {
button.Text = string.Format ("{0} clicks!",
count++); };
}
public override void OnConfigurationChanged
(Android.Content.Res.Configuration newConfig)
{
base.OnConfigurationChanged (newConfig);
Console.WriteLine("OnConfigurationChanged");
}
}
When I run the above, I see OnCreate, and when I rotate I see
OnConfigurationChanged, but I don't see any additional OnCreate messages.
> [Activity(ConfigurationChanges =
> Android.Content.PM.ConfigChanges.Orientation)]
> public class BaseActivity : Activity
Based on the name, are you subclassing BaseActivity? If you inherit from
BaseActivity you'll need to re-decare the [Activity] attribute along with the
ConfigurationChanges value; the custom attribute values are not "inherited" by
base classes.
> And i also tried setting ActivityAttribute.ConfigurationChanges on Manifest,
> but still not working.
>
> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
> android:installLocation="auto">
> <application android:icon="@drawable/grownotesmall">
> <activity android:name="BaseActivity"
> android:configChanges="orientation|keyboard|keyboardHidden"/>
I'm not sure if the above is valid (I don't see a /manifest/@package
attribute), and even if it were it (probably) wouldn't work as-is, because the
build process will generate a fully-qualified <activity/> element:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1" android:versionName="1.0" package="Scratch.Jni">
<application android:name="mono.android.app.Application"
android:debuggable="true">
<activity android:configChanges="orientation"
android:label="Scratch.Jni" android:name="scratch.jni.Activity1">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider android:name="mono.MonoRuntimeProvider"
android:initOrder="2147483647" android:authorities="Scratch.Jni.__mono_init__"
/>
</application>
<uses-sdk android:minSdkVersion="10"
android:targetSdkVersion="10" />
</manifest>
Note how the //activity/@android:name value is fully qualified as
"scratch.jni.Activity1".
If you use the "short name" ("BaseActivity", as you did), we won't detect it
and the resulting AndroidManifest.xml will contain both the short name and the
fully-qualified entry. If you want to provide your own XML fragment, you
likewise need to use a fully-qualified name
- Jon
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid