如何关闭应用程序时,多活动还活着 [英] how to close application when multiple activities are alive

查看:161
本文介绍了如何关闭应用程序时,多活动还活着的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开了3项活动。现在,用户要退出应用程序。为此,我必须完成所有的活动。不建议这样做,但我的应用程序要提供这样一个出口点的用户。如何关闭应用程序时,多活动活着

I have opened 3 activities. Now the user want to exit the application. for that I have to finish all the activities. It is not recommended to do this but My application wants to provide such an exit point to user. How to close application when multiple activities are alive

感谢

推荐答案

任何应用程序的所有actrivities使用相同的进程ID的机器人。这意味着只有一个次顶活动的停留和活动性份额,其通过其他活动创建的相同的过程。所以杀一个进程ID是一样的活动结束()。 如果你调用b活动从活动A.当activty B被杀死,然后你的控制来onResume()活动A的方法 您可以使用此行为。

All actrivities of any application use the same process id in android. that means only one activity stay at th top and that activity share the same process which was created by other activity. so killing an process id is same as finish() on activity. If you have called Activity B from activity A. when activty B is killed then your control comes to onResume() method of activity A. you can use this behaviour.

让你创建上点击一个按钮,你会退出应用程序。实现这一目标。设置点击该方法的静态布尔值。安德烈完成的活动。

let you have created a button on click of which you will exit the application. to achieve this. set a static boolean value on click of that method. andr finish the activity.

MyConstant.isApplicationTerminated = true;
finish();

现在在每一个延伸活动覆盖类 onResume()如下:

Now in every class which extends Activity override onResume() as follows

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
if(MyConstant.isApplicationTerminated){
        finish();
}
        super.onResume();
    }

在这种方式,您可以退出应用程序

In this way you can exit an application

谢谢 迪帕克

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

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