StartForeground () causes problems with the corridor

I use a service in my cordova application that generates a startForeground notification in onCreate. If the application was killed with a swipe and started again, the cordova device ready event no longer fires. It seems that the cordova object itself is not detected when the application restarts. The following error message appears:

E/Web Console(19472): Uncaught TypeError: Object #<Object> has no method 'exec' at file:///android_asset/www/src/jsFile.js:31

Line 31 and the following:

 cordova.exec(function (r) { if (callback) { callback(r); } }, function (err) { if (callback) { callback(false); } }, "Plugin", "functionName", []); 

The problem only occurs if I use startForeground in my service, if I comment on this part of the code, that everything works correctly. I desperately need help on these issues:

  • Can cordova handle be started manually?
  • How to start a service using startForeground , but still start the cordova-ready device after killing and restarting the application.

Edit:

After creating two quick project projects, one in Cordoba 3.6 (the version that I use for my actual application) and with Cordova 5.1, I realized that the problem does not occur in the new Cordoba version. However, I do not want to update because:

  • Never touch a running system.
  • I donโ€™t know that it can never work in the version ever since I installed many plugins in my application.
  • I'm lazy.

Any idea what could have changed from 3.6 to 5.1 that solved the error, and could I update my 3.6 code accordingly?

Edit2:

This is not a duplicate of this question . The deviceReady callback was mistaken in this question. This does not apply to my application, and it would be useless to work only when I do not use startForeground in my service.

+48
android service cordova hybrid-mobile-app
Aug 10 '15 at 9:50
source share
2 answers

You seem to have problems with the application life cycle. When you scroll or force close the application, the application process is killed, so when you restart, if you did not save the dependent objects or variables in the status package, they are returned as null, because activity assumes that these things are available. Can you insert the code that you have in onCreate() am guessing thats where your defining cord is.

+1
Aug 24 '17 at 8:14
source share
โ€” -

When JS is not written to the onDeviceReady() event onDeviceReady() - or Cordova WebView when Device already in the ready state - in this case the onDocumentReady() event will be at a different time.

try setting up a test script that logs when which event is fired; the difference between Device and Document Ready may be a culprit. verbose logging of JS and Logcat events.

you may need to bind JS events in different ways or move code between them to prevent a situation that looks like: reload a WebView when Device is ready, maybe some as an implementation attempt that works against the concept of using a JS application as part of a WebView implementation ? Without seeing the smallest code (rather, this โ€œexampleโ€ will not function, but there are broken links), I would assume that Service already running, and the application cannot start it.

This may be a functional example of what you are trying to archive.

Although the current version of Cordoba is more likely 7.0 than 5.1.

-one
Jun 20 '17 at 11:22 on
source share