什么是 Mono for Android 中的 [Application]? [英] What is [Application] in Mono for Android?

查看:42
本文介绍了什么是 Mono for Android 中的 [Application]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Mono 新手,正在学习 Mono For Android 教程.任何人都可以指点我一些文档来解释我的类上方 [Application] 标签的含义吗?...这是我的问题:

I'm new to mono and working through the Mono For Android tutorials. Can anyone point me to some documentation which explains the meaning of the [Application] tag above my classes?... Here's my issue:

我遇到了一个问题,我创建了两个单独的类 App1.cs &App2.cs,这两个都扩展了Application类(Public Class App1:Application...等)

I have come accross an issue where I have created two seperate classes App1.cs & App2.cs, both of these extend the Application Class (Public Class App1 : Application).. etc.

此声明 [Application] 上方有一个标记,尽管它构建良好,但似乎会导致部署问题.如果我注释掉其中之一,应用程序就可以正常构建和部署.

There is a tag above this declaration [Application] which seems to be causing deployment issues, although it builds fine. If I comment one of these out, the application builds and deploys fine.

我已经搜索了有关这些标签的信息,但在搜索、常见问题解答或谷歌上还没有找到任何内容……我猜是方括号导致了我的搜索问题.任何帮助都会很棒...

I have searched for info on these tags, but as yet cannot find anything in the search, FAQ's or on google... I guess the square brackes are causing me search problems. Any help would be great...

谢谢

C

推荐答案

在 Android 应用程序中,您可以将 Application 类,以便在您的应用中维护全局状态.一个应用程序最多可以有一个 Application 类,并且它在整个应用程序中共享.为了注册您的 Application 类,它需要在 AndroidManifest.xml(这适用于任何 Android 组件).Mono for Android 在编译期间使用属性生成清单,因此任何用 ApplicationAttribute 将在构建时生成配置.

In Android applications you can subclass the Application class in order to maintain global state in your app. An app can have at most one Application class, and it is shared throughout the app. In order to register your Application class it needs to be registered in AndroidManifest.xml (this applies to any Android component). Mono for Android uses attributes to generate the manifest during compilation, so any class decorated with ApplicationAttribute will generate configuration at build time.

由于只允许使用一个 Application 类,这可以解释您在尝试注册其中两个时遇到的问题.我的猜测(没有你在这里尝试做的事情的上下文)是你可能想要子类 Activity 用于这些类而不是 Application.

Since only one Application class is allowed, this would explain the problems you are seeing when you try to register two of them. My guess (without having context into what you're trying to do here) is that you probably want to subclass Activity for these classes instead of Application.

这篇关于什么是 Mono for Android 中的 [Application]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆