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( ...
随机推荐
- CSS之上边栏
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- CSS之Generator
这个工具可以,收藏一下.CSS Generator
- 查看EIGRP运行情况详细
配置EIGRP 在ROUTER(CONFIG)#下 router eigrp autonomous-system-number ROUTER(CONFIG-ROUTER)# network netwo ...
- ionic2 Navigation实现报错:No component factory found for "MyComponent"
ionic2 写的代码里面,跳转的时候报了一个 No component factory found for "RechargeSucceed" recharge() { let ...
- 8款给力HTML5/CSS3应用插件 可爱的HTML5笑脸
1.HTML5/CSS3实现笑脸动画 非常可爱 今天我们要分享一款基于纯CSS3实现的笑脸动画,我们只要在面部滑动鼠标,即可让人物的眼睛嘴巴动起来,实现微笑的效果,还挺可爱的. 在线演示 源码下载 2 ...
- 济南学习 Day 2 T3 am
[问题描述]m× m的方阵上有n棵葱,你要修一些栅栏把它们围起来.一个栅栏是一段沿着网格建造的封闭图形(即要围成一圈) .各个栅栏之间应该不相交.不重叠且互相不包含.如果你最多修k个栅栏,那么所有栅栏 ...
- Mac系统Finder访问资源库文件夹
Mac在Lion版本之后,默认隐藏了“资源库”文件夹,如果有时我们又需要访问它,该怎么办呢? 方法一 打开“Finder”,打开“前往”菜单时按住“Option”键. 方法二 我们也可设置Finder ...
- 【转】JavaScript里的this指针
用自然语言的角度理解JavaScript中的this关键字 <script type="text/javascript"> function ftn03(){ var ...
- C# 解析XML格式的字符串
public CreateOrderReturnResult GetCreateOrderReturnApi() { var result = new CreateOrderReturnResult( ...
- eclipse 4 rcp: java.lang.RuntimeException: No application id has been found.
错误详情: java.lang.RuntimeException: No application id has been found. at org.eclipse.equinox.internal. ...