问题
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.
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.
回答1:
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();
来源:https://stackoverflow.com/questions/19844889/mvvmcross-dataservice-in-an-android-broadcast-listener