究竟Activity.finish()方法是干什么的? [英] what exactly Activity.finish() method is doing?

查看:289
本文介绍了究竟Activity.finish()方法是干什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Android应用了一段时间,并遵循了很多关于活动生命周期的职位,以及应用程序的生命周期。

I'm developing android applications for a while, and followed a lot of posts about activity life cycle, and application's life cycle.

我知道 Activity.finish()法在路上的某个地方调用 Activity.onDestroy(),和也去除栈的活动,我想它在某种程度上指向操作系统和垃圾收集器,他可以做他的绝招,并释放内存时,它觉得这是一个很好的时间这样做......

I know Activity.finish() method calls somewhere in the way to Activity.onDestroy(), and also removing the activity from stack, and I guess it somehow points to operating system and garbage collector that he can "do his trick" and free the memory when it find it a good time doing so....

我来到了这个帖子 - <一href="http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon/2034238">Quitting一个应用程序? - 这是令人难以接受的并读马克·墨菲的答案

I came to this post - Quitting an application - is that frowned upon? and read Mark Murphy's answer.

这让我有点无所适从了完成()方法实际上做的事情。

it made me a bit confused about what the finish() method actually doing.

究竟完成()方法doind?

有机会的话,我会打电话完成()的onDestroy()将不会被调用?

there is a chance I'll call finish() and onDestroy() won't be called?

推荐答案

在调用完成()在一个活动中,该方法的onDestroy()执行此法能做这样的事情:

When calling finish() on an activity, the method onDestroy() is executed this method can do things like:

  1. 关闭该活动是管理任何对话框。
  2. 关闭酶活性管理任何光标。
  3. 在关闭所有打开搜索对话框

此外,的onDestroy()不是析构函数。它实际上并不破坏对象。只是,是基于一定的状态称为方法。所以,你的情况是还活着,很好*超类的的onDestroy()之后运行和returns.Android保持过程中周围的情况下,用户希望重新启动应用程序,这使得启动阶段更快。这个过程将不会做任何事情,如果内存需要被回收,这个过程会被杀死

Also, onDestroy() isn't a destructor. It doesn't actually destroy the object. It's just a method that's called based on a certain state. So your instance is still alive and very well* after the superclass's onDestroy() runs and returns.Android keeps processes around in case the user wants to restart the app, this makes the startup phase faster. The process will not be doing anything and if memory needs to be reclaimed, the process will be killed

这篇关于究竟Activity.finish()方法是干什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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