我如何可以通过编程关闭应用程序? [英] How can I programmatically close an application?

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

问题描述

我要寻找$ C $下一个按钮,完全关闭我的应用程序。

I am looking for code for a button that completely closes my app.

我试着用从谷歌的一些东西,但我的应用程序在后台仍在运行。我需要完全关闭。有code这样做吗?

I tried with some stuff from Google, but my app is still running in the background. I need to close it completely. Is there code that does this?

推荐答案

为什么你需要真正关闭您的应用程序?假设它只是一个正常的应用程序,不运行任何后台服务或持有wakelock(你知道,如果你在做这些事情),系统将任务管理的一个很好的工作,并最终将您的应用程序,如果是中背景和需要RAM中无需任何人工干预。一般来说,如果你只是完成()你的基地活动这会发生在自己,但几乎从来没有一个理由做到这一点。

Why do you need to really close your app? Assuming it's just a normal app and not running any background services or holding a wakelock (you'd know if you were doing those things), the system does a very good job of task management and will end your app if it's backgrounded and it needs the RAM without any manual intervention. Normally if you just finish() your base Activity this will happen on its own, but there's almost never a reason to do that.

(唯一的例外是如果你的应用程序以某种方式持有到引用业已完成的活动,这可能会导致难看的内存泄漏并防止关闭正常的应用程序,但你也可能知道,如果你正在做什么腥与覆盖应用程序的子类。)

(The only exception to this is if your Application is somehow holding onto references to already-finished Activities, which can cause ugly memory leaks and keep your app from closing normally, but you'd also probably know if you're doing anything fishy with an overridden Application subclass.)

这是99%的时间,如果你想强行关闭应用程序,您可能需要解决什么错误,在你的code使你认为该系统无法处理它自己,或者你需要重读对Android应用程序生命周期的文档再次(之前你,因为你应该已经阅读3次开始写一个Android应用程序。))

That is: 99% of the time if you want to forcibly close your Application, you either need to fix whatever bug in your code makes you think the system can't handle it on it's own, or you need to reread the documentation on the Android application lifecycle again (because you should have already read this 3 times before you started writing an Android app :)).

这篇关于我如何可以通过编程关闭应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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