This seems to be the Android standard:

[Activity(Label = "JiveTomTurkey", MainLauncher = true, Icon = "@drawable/icon")]
public class HyperActivity : Activity

...yet it seems redundant - if HyperActivity inherits from Activity, why does it also have to tell the compiler that the class is an Activity?

有帮助吗?

解决方案

I found this:

We mentioned earlier that Activities have to be registered in the AndroidManifest.xml file in order for them to be located by the OS, and the ActivityAttribute aids in doing just that. During compilation, the Xamarin.Android build process gathers all the attribute data from all the class files in the project and then creates a new AndroidManifest.xml which is based on the AndroidManifest.xml file in the project, but with the attribute data merged in. It then bundles that manifest into the resulting compiled application (apk file).

By using C# attributes, Xamarin.Android is able to keep the declarative information used to register an Activity together with the class definition. Failure to include this attribute will result in Android not being able to locate the Activity, since it would not be registered with the system.

here.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top