如何完成所有活动时,从子活动退出 [英] How to finish all activity when exit from child activity

查看:128
本文介绍了如何完成所有活动时,从子活动退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例子:我有3个活动,A,B和C的活动AI开放活动B,那么从B公开活动℃。然后我退出申请,$​​ C $ C:

Example : I have 3 Activities, A,B, and C. from Activity A I open Activity B then From B open Activity C. Then I exit application by code :

Intent intent = new Intent(Intent.ACTION_MAIN); 
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
System.exit(0);

我用这个$ C $下退出应用程序。但是,当重新启动应用程序,然后再返回到最近的活动。我的问题,如何完成活动时,从应用程序退出?

I use this code for exit app. But when restart app, back again to recent Activity. My question, How to finish all Activities when exit from app?

推荐答案

您必须回到你的主要活动首先由该code:

You must be back to your main activity first by this code:

Intent home = new Intent(this, mainActivity.class);
home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(home);

,然后你会退出你的应用程序mainActivity是这样的:

And then you will exit your application from mainActivity like this:

finish();
System.exit(0);

希望它帮助。

Hope it helps.

这篇关于如何完成所有活动时,从子活动退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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