在让用户做任何事情之前如何执行一些操作? [英] How to perform some actions before letting user to do anything?

查看:21
本文介绍了在让用户做任何事情之前如何执行一些操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在应用程序实际启动之前执行一些操作.

我试过了,但无法到达断点:

public class MyApplication : Android.App.Application {public MyApplication(IntPtr javaReference, JniHandleOwnership transfer):基地(javaReference,转移){}公共覆盖无效 OnCreate() {base.OnCreate();内部测试 = 1;//断点}}

我做错了吗?还是调试器有问题?

解决方案

这里的关键是使用 [Android.App.Application] 属性注册"您的自定义应用程序类.其次,您需要提供 OnCreate 覆盖以确保调用自定义应用程序类的构造函数.否则,如果没有 [Application] 属性,我们不会在 AndroidManifest.xml 中注册自定义

如果没有在上面的评论中定义名称,您将得到一个 md5 散列名称.

我们的架构文档中的一些注释也可能对这里有用:

https://developer.xamarin.com/guides/android/under_the_hood/架构/#Application_Startup

I need to perform some actions before application actually started.

I tried this but can't reach breakpoint:

public class MyApplication : Android.App.Application {
    public MyApplication(IntPtr javaReference, JniHandleOwnership transfer)
        : base(javaReference, transfer) { }

    public override void OnCreate() {
        base.OnCreate();
        int test = 1; //breakpoint
    }
}

Am I doing something wrong? Or here is some debugger problem?

解决方案

The key item here is to "Register" your custom Application class by using the [Android.App.Application] attribute. Secondly you need to provide an OnCreate override to ensure the custom application class's constructor is invoked. Otherwise without the [Application] attribute, we do not register the custom <application> element in the AndroidManifest.xml. Rather we use the default android.app.Application instead:

<application android:label="App6" android:name="android.app.Application" android:allowBackup="true" android:icon="@drawable/icon" android:debuggable="true">

Thus if we register using the [Application] attribute, we then will see our custom application class used instead:

<application android:label="App6" android:name="md50033386ba710bcf156abf7e9c48d30ef.MyApplication" android:allowBackup="true" android:icon="@drawable/icon" android:debuggable="true">

Here's a complete working example of this:

[Application] //Name is typically a good idea as well
public class MyApplication : Application
{
    public MyApplication(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
    { }
    public override void OnCreate()
    {
            base.OnCreate();
            int myInt = 1;
    }
}

Without a name defined in the comment above, you'll get a md5 hashed named instead.

There's a few notes in our Architecture docs that might be beneficial here as well:

https://developer.xamarin.com/guides/android/under_the_hood/architecture/#Application_Startup

这篇关于在让用户做任何事情之前如何执行一些操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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