如何使用code退出Android应用程序?如何使用、应用程序、code、Android

2023-09-12 04:35:55 作者:请叫我中路杀神

我相信这个问题已经被问的次数,因为我读了一些。我的客户希望我把一个按钮,进入他的应用程序,用户可以点击并退出。我已阅读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);

                }
            });