Android:何时以finish()结束课程? [英] Android: When to end class with finish()?

查看:106
本文介绍了Android:何时以finish()结束课程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常看到以 finish()结尾的类的示例,但肯定不是总是如此。我的问题是,何时应该以 finish()结束课程?它到底是做什么的,用后退按钮结束课程和用 finish()结束课程之间有什么区别?

I often see examples of classes which end with finish(), but definitely not always. My question is when should you end a class with finish()? And what does it do exactly, what is the difference between ending a class with the back button and ending it with finish()?

谢谢!

推荐答案

finish()可以被称为杀死(销毁)Activity实例。如果您不需要关闭活动手册(在许多情况下都是如此),则无需调用此方法。

finish() can be called to kill (destroy) an Activity instance. If you don't need to close your Activity manual, which is true in many cases, you don't need to call this method.

但是如果您需要一个按钮在活动中显示关闭的位置,则应使用此方法。但是一般来说,Android中的后退按钮行为可以处理类似这样的事情。

But if you require a button somewhere in your activity that says "close", then you should use this method. But in general the back button behavior in Android will handle things like this.

后退按钮实际上并未完成您的活动, finish()立即调用 onDestory()方法,而后退按钮则没有。

The back button does not actually finish your activity, finish() calls the onDestory() method right away, while the back button does not.

按下后退按钮时,将调用 onStop()方法,但可能会调用 onDestory()方法

When the back button is pressed, the onStop() method is called, but the onDestory() method call might be delayed by the system, this so that the Activity can be resumed by the system which is cheaper (in resources) than a full restart.

生命周期:
< a href = http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle rel = nofollow> http://developer.android.com/reference/android/app/Activity。 html#ActivityLifecycle

Finish():
http://developer.android.com/reference/android/app/Activity.html#finish()

Finish(): http://developer.android.com/reference/android/app/Activity.html#finish()

这篇关于Android:何时以finish()结束课程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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