kaiostech / sample-react

Simple example of a to-do list for KaiOS devices
https://developer.kaiostech.com/getting-started/build-your-first-app/sample-code#react
61 stars 22 forks source link

How to kill app process in kaios? #13

Closed inovramadani closed 4 years ago

inovramadani commented 4 years ago

I am developing an app that uses ws connection on kaios. When I press back and put the app in the background, somehow the app instance is not killed. I can still get message coming in from ws connection even though the app is in background. This makes the phone runs out of battery quickly because exited app remains in the runtime process I suppose.

But, I do need a situation where the app runs in background (not killed).

So, the question is, do we have access to kill an app process, for example when user press something or normally when app is closed and screen back to menu screen from app screen?

Ask also on SOF: https://stackoverflow.com/questions/60146146/dont-know-how-to-kill-app-process-in-kaios

seinlin commented 4 years ago

Call window.close() in the app will close the app process. So, you can observe the Backspace key and close the window.

Such as:

function handleKeydownEvent(e) {
  if (e.key == 'Backspace') {
    e.preventDefault();
    window.close();
  }
}
document.body.addEventListener("keydown", handleKeydownEvent);