如何杀死一个应用程序?

发布于 2024-11-26 05:28:11 字数 358 浏览 6 评论 0原文

我有一个具有超过 4 个活动的应用程序,但是当有人想要退出该应用程序时,他会再次获得所有活动。 现在我尝试使用退出代码:

this.finish()
android.os.Process.killProcess(android.os.Process.myPid())

等等。

但没有任何帮助我,所以我的问题是,有没有一种方法可以一次杀死所有活动,就像任务杀手一样?

编辑:

我自己找到了它:

当您启动第二个活动时,立即完成第一个活动:

startActivity(new Intent(...));
finish();

I have an app with more than 4 activities, but when somebody wants to exit the app, he gets all the activities again.
Now i've tried to use exit codes:

this.finish()
android.os.Process.killProcess(android.os.Process.myPid())

etc.

But nothing helps me, so my question is, is there an way to kill all the activities at one time, like a task killer?

Edit:

I've found it on myself:

When you launch the second activity, finish() the first one immediately:

startActivity(new Intent(...));
finish();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无妨# 2024-12-03 05:28:11

System.exit(0) 可以解决问题吗?

Does System.exit(0) do the trick?

旧情勿念 2024-12-03 05:28:11

尝试使用 getParent().finish() 捕获后退按钮; getParent() 返回调用当前活动的活动。如果你完成了父母,你也就完成了孩子。您还可以启动活动以获得结果,然后传递意图数据中的某些内容,您将在其中测试并一一完成每个活动。我不确定这是否是最好的、有效的解决方案。

Try getParent().finish() where you catch the back button; getParent() returns the activity that called current activity. And if you finish the parent, you finish the child. Also you can make start the activities for result and then pass something in the intent data on which you'll test and finish each activity one by one. I'm not sure if this is the best and working solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文