In my Application, I am trying to make a sync adapter service in Android which will run in the background when the app is killed.
This service will call WL.getInstance().sendActionToJS() to send the control to js.
I am using:
WL.App.setKeepAliveInBackground(true);
method to keep the app alive in Background, using this method I am able to use the instance to WL even though app is killed.
onSync.java:
try {
JSONObject data = new JSONObject();
data.put("isConnected", true);
data.put("connRes", "MOBILE");
WL wl = WL.getInstance();
if(wl!=null){
L.e("WL is not null");
wl.sendActionToJS("isConnected", data);
}
else{
L.e("WL is null");
}
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
main.js:
WL.App.setKeepAliveInBackground(true, options);
WL.App.addActionReceiver("MIActionReceiverId", function actionReceiver(received){
console.log('MIActionReceiverId . '+JSON.stringify(received));
else if(received.action == 'isConnected') {
//Connectivity manager
console.log('isConnected. ');
var isConnected = received.data.isConnected;
console.log('isConnected. '+isConnected);
}
}
WL.getInstance().sendActionToJS() method does nothing neither throwing any exception and addActionReceiver in main.js not receiving anything.
This is happening when app is killed and runnig the background rest of the time everything is working fine.