Kumaran
Kumaran

Reputation: 135

how trigger the 'exit' application event in nativescript with angular 2 in onclick of logout button view?

I want to exit the entire application in on Tap() of logout button in nativescript app. I referred the use of application events in below link. https://docs.nativescript.org/core-concepts/application-lifecycle

I want more idea on this?

Thanks in advance..

Upvotes: 3

Views: 6460

Answers (2)

Pavle Marinkovic
Pavle Marinkovic

Reputation: 59

  • Install "nativescript-exit" npm i nativescript-exit
  • Import exit function import { exit } from "nativescript-exit";
  • call exit function exit();

import { exit } from "nativescript-exit"; 
// to instal 'nativescript-exit' run in root folder(where node_modules are): 
// npm i nativescript-exit

public logOut(): void {
  exit(); // will close application
}
    <Button text="Log out" (tap)="logOut()"></Button>

Upvotes: 2

Eddy Verbruggen
Eddy Verbruggen

Reputation: 3550

I don't advocate exiting your app programmatically, but it can be done with a bit of code.

On iOS you'd do:

exit(0)

And on Android:

android.os.Process.killProcess(android.os.Process.myPid());

There's a plugin making it even easier for you: https://github.com/dvabuzyarov/nativescript-exit

Upvotes: 5

Related Questions