如何在 NativeScript 中使用 Angular 2 在注销按钮视图中触发"退出"应用程序事件?



我想在 nativescript 应用程序中注销按钮的 Tap(( 中退出整个应用程序。我在下面的链接中提到了应用程序事件的使用。 https://docs.nativescript.org/core-concepts/application-lifecycle

我想了解更多有关此的想法吗?

提前谢谢..

我不主张以编程方式退出您的应用程序,但可以通过一些代码来完成。

在 iOS 上,您可以执行以下操作:

exit(0)

在安卓上:

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

有一个插件让您更轻松:https://github.com/dvabuzyarov/nativescript-exit

  • 安装 "nativescript-exit"npm i nativescript-exit
  • 导入退出功能import { exit } from "nativescript-exit";
  • 呼叫退出功能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>

最新更新