I'm using a service in my cordova app which generates a startForeground
notification in the onCreate. If the app is killed via swipe and started again, the cordova device-ready event isn't fired anymore. It seems the cordova
object itsself is not defined when the app is restarted. I get the following error message:
E/Web Console(19472): Uncaught TypeError: Object #<Object> has no method 'exec' at file:///android_asset/www/src/jsFile.js:31
Line 31 and following:
cordova.exec(function (r) {
if (callback) {
callback(r);
}
}, function (err) {
if (callback) {
callback(false);
}
}, "Plugin", "functionName", []);
The problem only occurs if I use the startForeground
in my service, if I comment this part of the code out it's all working properly. I desperately need some help on these questions:
startForeground
, but still trigger the cordova device-ready after killing and restarting the appEdit:
After making two quick example projects, one in Cordova 3.6 (the version I'm using for my actual App) and on with Cordova 5.1, I realized that the problem does not occur in the new Cordova version. However I don't really want to update, because:
Any idea what could have changed from 3.6 to 5.1 that solved the bug, and whether I could update my 3.6 code accordingly?
Edit2:
This is not a duplicate of this question. The deviceReady callback was passed wrongly in this question. This is not the case in my app, and it wouldn't make sense to only work when I don't use startForeground
in my service.
It seems your having an issue surrounding your apps life cycle. When you swipe of or forcefully close the app, the apps process is killed so when restarting if you had not saved dependent objects or variables in the state bundle they will come back as null because the activity is assuming those things are available. Can you paste the code you have in the onCreate()
am guessing thats where your defining cordova.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With