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:
- connect to server
- 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)