Xamarin.android 在android应用程序中继承应用程序

Xamarin.android 在android应用程序中继承应用程序,xamarin.android,Xamarin.android,我有个小问题,可能没什么大不了的 我有一个小应用程序,它是这样启动的 namespace Paul.App { [Activity(Label = "@string/ApplicationName", MainLauncher = true, Theme = "@android:style/Theme.NoTitleBar", ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait, Icon =

我有个小问题,可能没什么大不了的

我有一个小应用程序,它是这样启动的

namespace Paul.App
{
    [Activity(Label = "@string/ApplicationName", MainLauncher = true, Theme =     "@android:style/Theme.NoTitleBar",
    ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait, Icon = "@drawable/icon")]
public class Paul : Application
{

    public static Paul Application;

    public Paul(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer)
    {
namespace Paul.App.Splash
{
[Activity(Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true)]
public class Splash : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
在这个应用程序中,我有

public Database dbm;
数据库是一个执行SQL操作的类

在这个名称空间中,我还有一个OnCreate,它调用一个新的活动,该活动以如下方式启动

namespace Paul.App
{
    [Activity(Label = "@string/ApplicationName", MainLauncher = true, Theme =     "@android:style/Theme.NoTitleBar",
    ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait, Icon = "@drawable/icon")]
public class Paul : Application
{

    public static Paul Application;

    public Paul(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer)
    {
namespace Paul.App.Splash
{
[Activity(Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true)]
public class Splash : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
这很好,一切都很好。除了一件事。我无法实例化数据库

如果我把它放进OnCreate或PaulIntPtr中。。。并在其他活动中使用

dbm=新的DBManager

启动时,如果我尝试使用PaulApplication.dbm访问dbm,它将返回null

如果我在Splash活动中这样做

((Paul)Application).dbm = new DBManager();
        if (((Paul)Application).dbm.SetupDB() != false)
        {
            Toast.MakeText(this, "Database failed to initialise", ToastLength.Long);
            return;
        }
调试器告诉我Paul不知名

这应该是一件简单的事情——我尝试实例化一次SQLite,然后在整个应用程序中使用它

这里的任何帮助都将不胜感激


Paul

在快速浏览代码时,我发现您正在用[Activity]属性装饰应用程序类,这是不正确的。相反,您要做的是使用,这将产生正确的AndroidManifest.xml输出。尝试将其更改为如下所示:

[Application(Label = "@string/ApplicationName", Icon = "@drawable/icon")]
public class Paul : Application
{
    // ...
}