[英]How to create Worklight instance without Android Activity
I am using MVVMCross framework for developing my Xamarin application . 我正在使用MVVMCross框架来开发Xamarin应用程序 。 I'm having challenges in using IBM Worklight APIs in the project. 在项目中使用IBM Worklight API时遇到了挑战。 The sample project that comes with IBM Worklight SDK initializes the Worklight Client instance by passing the Android Activity. IBM Worklight SDK随附的示例项目通过传递Android Activity来初始化Worklight Client实例。 However, when I use MVVM, I don't directly create any activity at all because all my functionality is in a ViewModel class in a separate PCL project . 但是,当我使用MVVM时,我根本不直接创建任何活动,因为我的所有功能都在单独PCL项目的ViewModel类中 。
First, I had challenge adding the IBM Worklight component in the PCL project because IBM worklight libraries are published only in Xamarin component store, but not in Nuget. 首先,我很难在PCL项目中添加IBM Worklight组件,因为IBM Worklight库仅在Xamarin组件存储中发布,而不在Nuget中发布。 I had to refer the IBM Worklight component in the Android Project and refer the Worklight.Android.dll in the PCL project to get the instances of classes I need. 我必须在Android项目中引用IBM Worklight组件,并在PCL项目中引用Worklight.Android.dll以获得我需要的类的实例。
Now the challenge is, I am not really sure how I can instantiate the Worklight Client instance from the View Model in a PCL project because the instance needs an Android Activity which I don't have . 现在的挑战是, 我不确定如何从PCL项目中的视图模型实例化Worklight Client实例,因为该实例需要一个我没有的Android Activity 。
Is there a way to create a Worklight client instance without an Android Activity? 有没有一种方法可以在没有Android Activity的情况下创建Worklight客户端实例?
See here: Why native WLClient lifecycle bind to Activity lifecycle 请参阅此处: 为什么本机WLClient生命周期绑定到Activity生命周期
The way Worklight is currently implemented is not ideal and could be improved. 当前实施Worklight的方式并不理想,可以改进。 The reason it is like this, is because WLClient has some features, such as displaying UI error messages, monitoring whether the app is in the foreground/background for heartbeat as well as push notifications support, that require an Android context. 之所以这样,是因为WLClient具有某些功能,例如显示UI错误消息,监视应用程序是否处于心跳的前台/后台以及需要Android上下文的推送通知支持。
I do not see how this can be worked-around at this time... 我目前不知道该如何解决...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.