Yes, I've also searched in the issues here and found the same issue reported: #438 But sadly that ticket is closed without a solution.
Android
I'm starting my plain TypeScript (without Angular) app. When I exit (or kill) the app, the event does not get fired. The event doesn't even get fired when I kill my app via button like the following: android.os.Process.killProcess(android.os.Process.myPid());
I need to mention that the suspendEvent is logged without any issues, as well as the launchEvent and the resumeEvent. Only exitEvent doesn't get triggered.
...
application.on(app.launchEvent, (args: app.ApplicationEventData) => {
console.log('app.ts -> launchEvent');
});
application.on(application.resumeEvent, (args: application.ApplicationEventData) => {
console.log("app.ts -> resumeEvent");
});
application.on(application.suspendEvent, (args: application.ApplicationEventData) => {
console.log('app.ts -> suspendEvent');
});
application.on(application.exitEvent, (args: application.ApplicationEventData) => {
console.log('app.ts -> exitEvent');
});
app.start({ moduleName: 'pages/main/main' });
Hello @svzi
I have created this sample application to demonstrate the exit event and it works as expected on my side.
Keep in mind that the exit event will be triggered when you press the Android back button on your device - pressing the home button will minimize the app (suspend event) and later it will be resumed (resume event).
Thanks @NickIliev, but I'm aware of how the events usually work. As I stated earlier, the resumeEvent fires as expect, when I minimize the app.
What circumstances could cause my issue, that the exitEvent doesn't get fired, even when I kill the process like I described in my initial post? I would expect the event to be fired, no matter if I kill the process via Android command (see above) or if I just close the window in the task manager, or select "kill all" in the task manager. I don't receive the exitEvent. 馃槥
@svzi this is the native behavior in Android. The same would happen if calling the native onDestroy.
More about this can be found here
Quote from Android documentation about onDestroy (which is the native event exposed with exitEvent in NativeScript):
Note: do not count on this method being called as a place for saving data! For example, if an activity is editing data in a content provider, those edits should be committed in either onPause() or onSaveInstanceState(Bundle), not here. This method is usually implemented to free resources like threads that are associated with an activity so that a destroyed activity does not leave such things around while the rest of its application is still running. There are situations where the system will simply kill the activity's hosting process without calling this method (or any others) in it, so it should not be used to do things that are intended to remain around after the process goes away.
Thanks for the explanation, @NickIliev!
Now I can understand why this app doesn't throw this event. But I'm still facing some serious issues because of that. My app plays a some voice via TTS (https://github.com/bradmartin/nativescript-texttospeech) and I want the app to stop talking, as soon as the app gets closed. Currently the speech engine doesn't stop talking, when I kill the app. That's somewhat annoying. And I don't want it to stop when I minimize it (suspendEvent). Any ideas or recommendations?
Same problem here, I want to set a firstrun flag when the application is ran but it has been closed by killing it.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.