如何在没有启动活动的情况下初始化MvvmCross框架? [英] How do I initialize the MvvmCross framework without a splash Activity?

查看:99
本文介绍了如何在没有启动活动的情况下初始化MvvmCross框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我正在创建一个广播接收器,它将监听网络变化.在OnReceive中,它将检查设备是否刚刚连接到WiFi,然后开始在后台上传.没有活动显示,那么在没有启动活动的情况下如何初始化框架?我不需要框架的任何页面导航部分,因此精简的初始化将是最佳选择.

In my app I am creating a broadcast receiver which will listen for network changes. In the OnReceive it will check whether the device has just connected to WiFi and then start uploading in the background. No Activities will be shown so what do I need to do to initialize the framework without a splash Activity? I won't need any of the page navigation parts of the framework so a stripped down initialization would be optimal.

    private override void OnReceive(Context context, Intent intent)
    {
        bool isWifiConnected = false;
        bool isMobileConnected = false;

        if (intent.Action.Equals(ConnectivityManager.ConnectivityAction))
        {
            NetworkInfo networkInfo = (NetworkInfo)intent.GetParcelableExtra(ConnectivityManager.ExtraNetworkInfo);


            if (networkInfo.IsConnected)
            {
                if (networkInfo.Type == (int)ConnectivityType.Wifi)
                {
                    isWifiConnected = true;
                }
                if (networkInfo.Type == (int)ConnectivityType.Mobile)
                {
                    isMobileConnected = true;
                }
            }
        }

        if (isWifiConnected)
        {
            StartUp(); //What do I put in this private method?
        }

推荐答案

我现在对GitHub进行了一些更改,希望可以使您使用其BroadcastReceiver创建应用.

I have now pushed some changes to GitHub which should hopefully enable you to create your app with its BroadcastReceiver.

使用这些修改,您现在可以使用以下代码从任何应用程序组件-Activity,BroadcastReceiver,Service或ContentProvider初始化核心应用程序

Using these modifications, you can now initialize the core application from any Application Component - Activity, BroadcastReceiver, Service or ContentProvider - using code like:

var setup = MvxAndroidSetupSingleton.GetOrCreateSetup(this.ApplicationContext);
setup.EnsureInitialized(this.GetType());

这些更改应使MvvmCross应用程序可以在"Intent.ActionMain"方案以及以下情况下启动:

These changes should enable an MvvmCross application to be started in "the Intent.ActionMain" scenario, as well as in the situations:

  • 当应用清单中的第二个Intent是请求时
  • 当请求服务,BroadcastReceiver或ContentProvider组件时
  • 由于Android操作系统先前已将应用程序清除出内存而请求重新启动,但用户现在已请求重新启动应用程序(有点像WP7中的逻辑删除后的水合作用)

关于这些更改的详细说明是 http: //slodge.blogspot.co.uk/2012/05/android-application-initialization-and.html

A more lengthy explanation of these changes is http://slodge.blogspot.co.uk/2012/05/android-application-initialization-and.html

这篇关于如何在没有启动活动的情况下初始化MvvmCross框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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