简体   繁体   English

如何在没有Android活动的情况下创建Worklight实例

[英]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.

相关问题 如何在一个活动的Android中创建实例变量? - How to create an instance variable in one activity Android? 我如何在不更改satic变量的情况下创建相同活动的新实例? - How can i create new instance of same activity without change satic variables in android? 如何在Android中创建实例以调用服务类的活动方法? - How to create an instance to call a method of an activity to a service class in Android? Android Start活动无需创建新实例 - Android Start activity without creating new instance Worklight 6.0-如何使用Dojo 1.9和Worklight 6.0为Android 2.2创建和部署Dojo启用Worklight混合应用程序 - Worklight 6.0 - how to create and deploy dojo enable worklight hybrid application for android 2.2 using dojo 1.9 and worklight 6.0 Android创建当前活动的新实例 - Android create new instance of current activity Android活动创建我的线程的多个实例 - android activity create multiple instance of my thread 如何在不扩展Activity的情况下在android中动态创建按钮 - How to create a button dynamically in android without extending Activity 如何在android studio中创建没有主要活动的应用程序? - How do I create an application without a main activity in android studio? 如何保存实例活动而不刷新? - how to save instance the activity without refreshing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM