我该如何退出我的应用程序? [英] How can I exit from my app?

查看:68
本文介绍了我该如何退出我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从我的应用程序退出?

How can I exit from my app?

我希望当用户点击按钮时,
应用程序将完全退出,我看到了关于它的任何答案,但他们把应用程序带到了后端,

I want that when the user will clicked on the button, the app will exit completely, I saw any answers about it, but they took the app to backend,

我想完全退出

推荐答案

在这个方法中你可以在任何地方调用 exit()函数并退出应用程序。所以要在任何时候关闭应用程序,请在Intent&中使用 FLAG_ACTIVITY_CLEAR_TOP 标志。然后是system.exit();

in this method you have can call exit() function anywhere and get exit from the app. so For closing an app at any point use FLAG_ACTIVITY_CLEAR_TOP flag in Intent & then system.exit();

注意:我认为它不会破坏Android生命周期

NOTE : I think in way it will not break the Android Life cycle

在您需要从应用程序执行EXIT的地方

public void exit() {
    startActivity(new Intent(this, HomeActivity.class).
    setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK).putExtra(EXIT_FLAG, true));
}

MainActivity.onCreate()

protected void onCreate(Bundle savedInstanceState) {
    if (getIntent().getBooleanExtra(EXIT_FLAG, false)) {
        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) {
            finish();
    }
}

这篇关于我该如何退出我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆