Android广播侦听器中的MvvmCross DataService [英] MvvmCross DataService in an Android Broadcast listener

查看:54
本文介绍了Android广播侦听器中的MvvmCross DataService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试进入MvvmCross领域,并取得了一些不错的进展,但是遇到了一些我自己无法解决的问题.我目前有一个将一直运行的android服务.该服务将在系统启动时或应用程序首次启动时启动.

I am currently venturing into the MvvmCross realm and making some good headway, but ran into something that I have been unable to figure out on my own. I currently have an android service that is going to be running all the time. That service is going to be started either on a system boot or when the application first fires up.

该服务/广播接收者将需要访问使用MvvmCross在PCL项目中创建的DataService.由于没有任何与服务相关联的视图模型,因此我无法在创建服务时弄清楚如何将实例化的数据服务添加到该服务/广播接收器中.

That service/broadcast receiver will need access to the DataService that is created in a PCL project with MvvmCross. I have not been able to figure out how to get the instantiated data service into that service/broadcast receiver on creation of the service since there are not any view models that are associated with the service.

我知道它可能相对简单,但我还没有自己弄清楚.

I know that it's probably relatively simple, but I haven't been figure it out on my own.

推荐答案

最简单的方法可能是只请求在OnCreate的第一部分中为您的服务完成完整的Setup:

The easiest way to do this is probably to just request that the full Setup is completed during the first part of OnCreate for your service:

        var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);
        setupSingleton.EnsureInitialized();

这篇关于Android广播侦听器中的MvvmCross DataService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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