为什么本地WLClient生命周期绑定到活动的生命周期 [英] Why native WLClient lifecycle bind to Activity lifecycle

查看:209
本文介绍了为什么本地WLClient生命周期绑定到活动的生命周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

短版

我发现WLClient生命周期势必活动。活动的生命周期是由操作系统管理。

你有任何建议,以弥补这一点?

长版

有关Android原生项目,第一步应该是下面的调用创建一个WLClient实例

  WLClient.getInstance(上下文CTX)
 

从API文档,这是一个背景下,没有一个活动,但在现实中,也就会WLPush.java类型转换的WL框架。

这是没有意义的一个WLClient绑定到一个活动,它的生命周期不是由我们来控制的。因此,对于安全问题,每个WLClient应重新创建,在创建新的活动时。

和对每个再创造,以下需要:

  1. 连接到服务器
  2. 构造挑战处理器

我有以下错误,如果我通过一个类(MainContext)继承应用程序(这是一个上下文):

  09-26 13:33:29.571:E / AndroidRuntime(32300):致命异常:池2线程4
09-26 13:33:29.571:E / AndroidRuntime(32300):工艺:com.XXXX,PID:32300
09-26 13:33:29.571:E / AndroidRuntime(32300):java.lang.ClassCastException:com.XXX.MainContext不能转换为android.app.Activity
。09-26 13:33:29.571:E / AndroidRuntime(32300):在com.worklight.wlclient.api.WLPush< INIT>(WLPush.java:151)
09-26 13:33:29.571:E / AndroidRuntime(32300):在com.worklight.wlclient.api.WLClient.getPush(WLClient.java:673)
09-26 13:33:29.571:E / AndroidRuntime(32300):在com.worklight.wlclient.WLRequest.requestFinished(WLRequest.java:203)
09-26 13:33:29.571:E / AndroidRuntime(32300):在com.worklight.wlclient.InternalRequestSender.run(AsynchronousRequestSender.java:138)
09-26 13:33:29.571:E / AndroidRuntime(32300):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
09-26 13:33:29.571:E / AndroidRuntime(32300):在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:587)
09-26 13:33:29.571:E / AndroidRuntime(32300):在java.lang.Thread.run(Thread.java:841)
 

解决方案

目前的实现并不理想。如果你愿意,你可以提交功能请求有这样的重新评估在将来的版本。 http://www.ibm.com/developerworks/rfe/ :您可以通过提交

它之所以这样,是因为 WLClient 有一些功能,比如显示用户界面的错误信息,监控应用程序是否在前台/后台的心跳为以及推送通知的支持,需要一个Android上下文。

在这种情况下,预计你所得到的误差。

Short Version

I've found that WLClient lifecycle is bound to Activity. Activity lifecycle is managed by OS.

Do you have any recommendations to compensate this?

Long Version

For Android Native project, the first step should be create a WLClient instance by the following call

WLClient.getInstance(Context ctx)

From the API document, it's a Context, not an Activity, but in reality, there would be a type cast in WLPush.java in WL framework.

It doesn't make sense to bind a WLClient to a Activity, whose life cycle is not controlled by us. So for the safety concern, each WLClient should be re-created, when a new Activity is created.

And for each re-creation, the following are needed:

  1. connect to server
  2. construct challenge handler

I have the following error if I passed a class (MainContext) inheriting Application (which is a Context):

09-26 13:33:29.571: E/AndroidRuntime(32300): FATAL EXCEPTION: pool-2-thread-4
09-26 13:33:29.571: E/AndroidRuntime(32300): Process: com.XXXX, PID: 32300
09-26 13:33:29.571: E/AndroidRuntime(32300): java.lang.ClassCastException: com.XXX.MainContext cannot be cast to android.app.Activity
09-26 13:33:29.571: E/AndroidRuntime(32300):    at com.worklight.wlclient.api.WLPush.<init>(WLPush.java:151)
09-26 13:33:29.571: E/AndroidRuntime(32300):    at com.worklight.wlclient.api.WLClient.getPush(WLClient.java:673)
09-26 13:33:29.571: E/AndroidRuntime(32300):    at com.worklight.wlclient.WLRequest.requestFinished(WLRequest.java:203)
09-26 13:33:29.571: E/AndroidRuntime(32300):    at com.worklight.wlclient.InternalRequestSender.run(AsynchronousRequestSender.java:138)
09-26 13:33:29.571: E/AndroidRuntime(32300):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
09-26 13:33:29.571: E/AndroidRuntime(32300):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
09-26 13:33:29.571: E/AndroidRuntime(32300):    at java.lang.Thread.run(Thread.java:841)

解决方案

The current implementation is not ideal. If you'd like, you can submit a feature request to have this re-evaluated for a future release. You can submit it via: http://www.ibm.com/developerworks/rfe/

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.

In this case, the error you are getting is expected.

这篇关于为什么本地WLClient生命周期绑定到活动的生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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