Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin still running after navigator.app.exitApp() #3

Closed
HuaHub opened this issue Jan 14, 2014 · 11 comments
Closed

Plugin still running after navigator.app.exitApp() #3

HuaHub opened this issue Jan 14, 2014 · 11 comments

Comments

@HuaHub
Copy link

HuaHub commented Jan 14, 2014

The flashlight still runs after navigator.app.exitApp() is called.

It doesn't help to use "window.plugins.flashlight.switchOff();", it is still running which makes it impossible for other apps to use the camera if the flashlight app isn't forced stopped.

Solution?

@EddyVerbruggen
Copy link
Owner

Hi, are you calling exitapp in the callback handler of switchoff? If not, do you give the switchoff function sufficient time to perform the actual switch?

@HuaHub
Copy link
Author

HuaHub commented Jan 14, 2014

Hi, no I*m not calling exitapp in the callback of switchoff. Could you please show how?

It seems like enough time to switchoff to perform the actual switch, because if the camera is on and i press the backbutton, the switch is turned off before the app is closing. My code looks like this:
document.addEventListener("backbutton", function(){
window.plugins.flashlight.switchOff();
navigator.app.exitApp();
}, false);

Thanks for quick response Eddy :>

@EddyVerbruggen
Copy link
Owner

Hi, try it like this and let me know what happens. It defines a callback function (exitApp) which is invoked when the switchOff function returns from native code back to Javascript (the callback):

function exitApp() {
navigator.app.exitApp();
}

document.addEventListener("backbutton", function(){
window.plugins.flashlight.switchOff(exitApp,exitApp)
}, false);

@HuaHub
Copy link
Author

HuaHub commented Jan 14, 2014

I see what you're thinking, but somehow it seems like the same (except now we're 100% sure that the flashlight.switchOff is finished). The flashlight is shutdown, and exitApp is called and everything is looking alright. But it still runs in the background even though the app isnt running...

The only way to fix it is to go to the Task Manager and force stop the app. May that be an indicator that the app is not exited properly, but on the other hand the app disappears from "running apps" in task manager when backbutton is pushed... Kinda a contradiction.

@EddyVerbruggen
Copy link
Owner

Hi, I will try to find some time and try this myself.

One more question: does switchOff work in other cases (not while exiting the app)? If so, you could try wrapping exitApp in a timeout to give it some more time to switch the light off:

setTimeout(function() {
navigator.app.exitApp();
}, 1000); // 1 second

@HuaHub
Copy link
Author

HuaHub commented Jan 15, 2014

Hi, yes, switchOff work in other cases just fine. I tried your suggestion, but it doesn't help. :(

I think the problem may be that flashlight.switchOff() is not "complete", even though the flash is shut off, it still occupies the camera. Because if the flashlight is toggled off and the app is shutdown (without having to call switchOff()) the camera is still occupied.

Would you like me to push my code so you could try it yourself? It's just about 10 lines of code for the flashlight.

@EddyVerbruggen
Copy link
Owner

Yes please do. Thanks!

@HuaHub
Copy link
Author

HuaHub commented Jan 15, 2014

Here it is :)

https://github.com/HuaHub/flashlight

1 similar comment
@HuaHub
Copy link
Author

HuaHub commented Jan 15, 2014

Here it is :)

https://github.com/HuaHub/flashlight

@EddyVerbruggen
Copy link
Owner

Hi!

You're on to something... when exiting the app with exitApp (and after switching the light off), the camera seems to remain occupied.
This can be observed by starting the regular Camera app, which is denied access to the camera. This needs to be fixed, but I have to investigate why this happens..

@EddyVerbruggen
Copy link
Owner

Hi @HuaHub,

I was able to fix the problem you reported! I've just submitted it to the repo and PhoneGap Build. I've added your github name to the README credits because I think it was quite an import bugfix for Android developers.

Thanks again for pointing this out to me,
Eddy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants