How to use Android Activity's finish(), onDestory() and System.exit(0) methods
Activity.finish()
Calling this method will let the system know that the programmer wants the current Activity to be finished. And hence, it calls up onDestroy() after that.
The system will remove the top level activity from stack when calling finish(). However the system will not call onDestory() immediately so that means allocated resources aren’t free at the moment. Since the activity is removed form the stack, you won’t be able to go back the activity when you press the ‘back’ button. Actually onDestroy() is not just triggered by finish(), the system can call it on it’s own as well.
Activity.onDestory()
The final cleanup method, destroying this instance and freeing up resources.
The last state in the Activity Life-cycle. All resources will be gone. You should free up resources that you can on your own, e.g. closing open connections, readers, writers, etc. But if you don’t override it, the system does what it has to. When you want to re-enter this activity, it must be re-created and executing onCreate() method
System.exit(0)
This method will exit the application. It will kill the process of this application.
One last thing
In one of my own project, I call the finish() method based on the requirement.
My project has only 3 pages and the transitions as follow:
Main Page <--> Login Page <--> Signup Page
There is a back button in the Signup Page, it is to back to last activity to login. When I was first testing on the button, it didn’t work as I expected as
Main Page <-- Login Page <-- Signup Page
It worked as: Login Page <–> Signup Page and after a few cycles, it then back to the Main Page。
As new activity was always been created, and pushed on the stack. It will be pulled one by one, so it will shows like that.
The transition is been performed by calling startActivity(new Intent(…..)). After some studies, the finish() method should be called based on the situation.
How to use Android Activity's finish(), onDestory() and System.exit(0) methods的更多相关文章
- android Activity类中的finish()、onDestory()和System.exit(0) 三者的区别
android Activity类中的finish().onDestory()和System.exit(0) 三者的区别 Activity.finish() Call this when your a ...
- 安卓开发-Activity中finish() onDestroy() 和System.exit()的区别
Activity.finish()Call this when your activity is done and should be closed. 在你的activity动作完成的时候,或者Act ...
- 安卓开发-Activity中finish() onDestroy() 和System.exit()的区别(转)
Activity.finish()Call this when your activity is done and should be closed. 在你的activity动作完成的时候,或者Act ...
- android Process.killProcess 和 System.exit(0) 区别
1 Process.killProcess 和 System.exit(0) 两个都会 kill 掉当前进程. 你可以打开 DDMS 查看进程号,或 adb shell 进入 shell 然后 ps ...
- android开发时,finish()跟System.exit(0)的区别
这两天在弄Android,遇到一个问题:所开发的小游戏中有背景音乐,玩的过程中始终有音乐在放着,然后在我退出游戏后,音乐还在播放! 我看了一下我最开始写的退出游戏的代码,就是简单的finish() ...
- android finish和system.exit(0)的区别
finish是Activity的类,仅仅针对Activity,当调用finish()时,只是将活动推向后台,并没有立即释放内存,活动的资源并没有被清理:当调用System.exit(0)时,杀死了整个 ...
- Android:finish()与System.exit(0)之间的区别
finish()与System.exit(0)都是用来退出.但是两者还是有一定的区别: finish是Activity的类,仅仅针对Activity,当调用finish()时,只是将活动推向后台,并没 ...
- System.exit(0);和finish();,push原理
今天师姐问我安卓后台的问题,想起几年前做进制转换的时候特意研究了一下怎么才能「不驻留内存地退出」.虽然Android不推荐用户手动关闭进程,但是在那个内存捉襟见肘的年代,不得不考虑内存. 首先直接按b ...
- 【Android】System.exit(0) 退出程序
许多 Android 应用程序都是连续点击两下返回键时退出程序,代码如下: private long exitTime = 0; @Override public boolean onKeyDown( ...
随机推荐
- 【转载】Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
http://blog.csdn.net/congcong68/article/details/41113239 互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及 ...
- 二维码zxing源码分析(四)wifi部分
前三个部分的地址是:ZXING源码分析(一)CAMERA部分 . zxing源码分析(二)decode部分.zxing源码分析(三)result.history部分 前面三篇文章基本上已经把zxin ...
- Linux命令(2):ls命令
1.作用:列出目录的内容: 2.格式:ls [选项] [文件] [选项]为指定要查看文件相关的内容,若未指定文件默认查看当前目录下的所有文件: 3.常见参数: 如图: 4.使用实例: [yournam ...
- 基于jquery的inputlimiter 实现字数限制功能
html代码: <td>内容摘要:</td> <td> <textarea id="content_summary" rows=5 nam ...
- Cocos2d-JS中的cc.LabelTTF
cc.LabelTTF是使用系统中的字体,它是最简单的标签类.cc.LabelTTF类图如下图所示,可以cc.LabelTTF继承了cc.Node类,具有cc.Node的基本特性. LabelTTF类 ...
- 20150309—bs的保存状态
http:保存状态方式,传值方式 session:(会话) 默认过期时间20分钟(20分内无任何操作自动销毁),针对用户独立,一般用来存储少量信息的 存值:session[“name”]=data;( ...
- 分享web前端七款HTML5 Loading动画特效集锦
以前我们大部分的Loading动画都是利用gif图片实现的,这种图片实现Loading动画的方法虽然也很不错,但是作为HTML5开发者来说,如果能利用HTML5和CSS3实现这些超酷的Loading动 ...
- Qt获得网页源码
1.工程中添加网络模块 打开你的.pro文件插入以下代码 QT += network 2.添加代码 CodeQString NetWork::getWebSource(QUrl url) { QNet ...
- python+selenium环境配置(windows7环境)
下载python[python开发环境] http://python.org/getit/ 下载setuptools[python的基础包工具] http://pypi.python.org/pypi ...
- oc常见误区
1.同步请求可以从因特网请求数据,一旦发送同步请求,程序将停止用户交互,直至服务器返回数据完成,才可以进行下一步操作, 2.异步请求不会阻塞主线程,而会建立一个新的线程来操作,用户发出异步请求后,依然 ...