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( ...
随机推荐
- U3D 飞机大战(MVC模式)解析--面向对象编程思想
在自己研究U3D游戏的时候,看过一些人的简单的游戏开发视频,写的不错,只是个人是java web 开发的人,所以结合着MVC思想,对游戏开发进行了一番考虑. 如果能把游戏更加的思想化,分工化,开发便明 ...
- (转)Android之自定义适配器
ListView作为一个实际开发中使用率非常高的视图,一般的系统自带的适配器都无法满足开发中的需求,这时候就需要开发人员来自定义适配器使得ListView能够有一个不错的显示效果. 有这样一个Demo ...
- GitHub之创建
O(∩_∩)O~ 爱“搞事”的我又创了一个Github账号,和当初加入博客园的初衷一样,为了广泛交流和学习而已.很久之前我就发现了有很多人都在使用GitHub,然而当时看不懂英文(绝大部分都是英文), ...
- Cocos2d-JS动画
与动作密不可分的还有动画,动画又可以分为场景过渡动画和帧动画.场景过渡动画我们在以往介绍过,这一个我们只介绍帧动画.帧动画帧动画就是按一定时间间隔.一定的顺序.一帧一帧地显示帧图片.我们的美工要为精灵 ...
- C语言知识总结(2)
选择结构-if if(表达式) {} {}为作用域 多重if-else 例如: #include <stdio.h> int main(){ ; ){ printf("没有购物 ...
- (转)RabbitMQ消息队列(二):”Hello, World“
本文将使用Python(pika 0.9.8)实现从Producer到Consumer传递数据”Hello, World“. 首先复习一下上篇所学:RabbitMQ实现了AMQP定义的消息队列.它实现 ...
- 冒泡,快排算法之javascript初体验
引子:javascript实际使用的排序算法在标准中没有定义,可能是冒泡或快排.不用数组原生的 sort() 方法来实现冒泡和快排. Part 1:冒泡排序(Bubble Sort) 原理:临近的两数 ...
- 济南学习 Day 2 T3 pm
它[问题描述]N个人坐成一圈,其中第K个人拿着一个球.每次每个人会以一定的概率向左边的人和右边的人传球.当所有人都拿到过球之后,最后一个拿到球的人即为胜者.求第N个人获胜的概率. (所有人按照编号逆时 ...
- Java开发者常犯的十个错误
翻译自:Top 10 Mistakes Java Developers Make 文章列出了Java开发者最常犯的是个错误. 1.将数组转换为ArrayList 为了将数组转换为ArrayList,开 ...
- 如何在CentOS5中增加CentALT的源
1. 建立centalt.repo 指令: vi /etc/yum.repos.d/centalt.repo 2. 將下面的內容貼進去 [CentALT] name=CentALT ...