简体   繁体   中英

How to create Worklight instance without Android Activity

I am using MVVMCross framework for developing my Xamarin application . I'm having challenges in using IBM Worklight APIs in the project. The sample project that comes with IBM Worklight SDK initializes the Worklight Client instance by passing the Android Activity. 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 .

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. 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.

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 .

Is there a way to create a Worklight client instance without an Android Activity?

See here: Why native WLClient lifecycle bind to Activity lifecycle

The way Worklight is currently implemented is not ideal and could be improved. 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.

I do not see how this can be worked-around at this time...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM