且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何关闭应用程序时,多活动还活着

更新时间:2023-10-18 14:35:04

任何应用程序的所有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

谢谢 迪帕克