我想在 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>