如何使用code退出Android应用程序? [英] How to exit an android app using code?

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

问题描述

我相信这个问题已经被问的次数,因为我读了一些。我的客户希望我把一个按钮,进入他的应用程序,用户可以点击并退出。我已阅读<一个href="http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon/2034238">this并发现主叫完成()将做到这一点。但是,完成只关闭当前运行的活动吗?我有很多的活动,所以在这种情况下,我要通过每一个活动的实例,并完成他们还是尽一切活动到Singleton模式。

I am sure this question has been asked number of times because I read few. My client wants me to put a button into his app where users can click and exit. I have read this and found calling finish() will do it. But, finish is only closing the current running activity right? I have lot of activities so in this case I have to pass each and every activity's instance and finish them or make every activity into Singleton pattern.

我也认识了 Activity.moveTaskToBack(真)可以让你进入主屏幕。 OK,这不是关闭而是一个后台进程。因此,这是有效的?

I also got to know Activity.moveTaskToBack(true) can get you into the home screen. OK, this is not closing but backgrounding the process. So is this is effective?

哪种方法我应该用完全关闭该应用程序?任何上述或上述方法的任何其他方法/其他使用?

Which method should I use to close the app COMPLETELY? Any of above described or any other method/other usage of above methods?

请帮忙。

推荐答案

您可以调用System.exit();摆脱所有的acivities的。

You can call System.exit(); to get out of all the acivities.

    submit=(Button)findViewById(R.id.submit);

            submit.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
android.os.Process.killProcess(android.os.Process.myPid());
                    System.exit(1);

                }
            });

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

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