2

How to exit my app with a button? Instead of explaining to my users how to exit from the app, I want to add an button that will terminate my app so they won't call for help.

Yes there are still people don't know how to "Launch the recent applications menu"

Cem Kaan
  • 2,086
  • 1
  • 24
  • 55

1 Answers1

4

You could do this,

import * as application from "@nativescript/core/application";


...

if (application.android) {
   application.android.foregroundActivity.finish();
} else {
   exit(0);
}
Cem Kaan
  • 2,086
  • 1
  • 24
  • 55
Manoj
  • 21,753
  • 3
  • 20
  • 41
  • 1
    It's not the same as "clearing app from memory". I need the app to turn back to main.js and run from begining. – Cem Kaan Apr 06 '20 at 08:20
  • 1
    The above code terminates the app and it will restart from main or app js. If you have issues please share a Playground sample. – Manoj Apr 06 '20 at 09:09
  • One thing to keep in mind is adding functionality to exit/kill the app to prod version may cause rejection from the Apple as they're not recommending killing the app because it may look like the app crashed to the user. More info here: https://developer.apple.com/library/archive/qa/qa1561/_index.html – Andrew Mykhalchuk Jan 26 '21 at 10:31