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的更多相关文章

  1. android Activity类中的finish()、onDestory()和System.exit(0) 三者的区别

    android Activity类中的finish().onDestory()和System.exit(0) 三者的区别 Activity.finish() Call this when your a ...

  2. 安卓开发-Activity中finish() onDestroy() 和System.exit()的区别

    Activity.finish()Call this when your activity is done and should be closed. 在你的activity动作完成的时候,或者Act ...

  3. 安卓开发-Activity中finish() onDestroy() 和System.exit()的区别(转)

    Activity.finish()Call this when your activity is done and should be closed. 在你的activity动作完成的时候,或者Act ...

  4. android Process.killProcess 和 System.exit(0) 区别

    1 Process.killProcess  和 System.exit(0) 两个都会 kill 掉当前进程. 你可以打开 DDMS 查看进程号,或 adb shell 进入 shell 然后 ps ...

  5. android开发时,finish()跟System.exit(0)的区别

      这两天在弄Android,遇到一个问题:所开发的小游戏中有背景音乐,玩的过程中始终有音乐在放着,然后在我退出游戏后,音乐还在播放! 我看了一下我最开始写的退出游戏的代码,就是简单的finish() ...

  6. android finish和system.exit(0)的区别

    finish是Activity的类,仅仅针对Activity,当调用finish()时,只是将活动推向后台,并没有立即释放内存,活动的资源并没有被清理:当调用System.exit(0)时,杀死了整个 ...

  7. Android:finish()与System.exit(0)之间的区别

    finish()与System.exit(0)都是用来退出.但是两者还是有一定的区别: finish是Activity的类,仅仅针对Activity,当调用finish()时,只是将活动推向后台,并没 ...

  8. System.exit(0);和finish();,push原理

    今天师姐问我安卓后台的问题,想起几年前做进制转换的时候特意研究了一下怎么才能「不驻留内存地退出」.虽然Android不推荐用户手动关闭进程,但是在那个内存捉襟见肘的年代,不得不考虑内存. 首先直接按b ...

  9. 【Android】System.exit(0) 退出程序

    许多 Android 应用程序都是连续点击两下返回键时退出程序,代码如下: private long exitTime = 0; @Override public boolean onKeyDown( ...

随机推荐

  1. 代码研磨 Slim v3 (一)--app->get()&route->add()

    index.php代码如下: $app->get('/forbase', function ($request, $response, $args){ Example\Module\Base:: ...

  2. 小菜鸟带着梦想学chromium

    风雨送春归, 飞雪迎春到. 已是悬崖百丈冰, 犹有花枝俏. 俏也不争春, 只把春来报. 待到山花烂漫时, 她在丛中笑. 这首卜算子·咏梅可是应了我的心情了.最近换工作,受到频频打击,面试过程中发现满世 ...

  3. 《Cocos2d-x实战 JS卷 Cocos2d-JS开发》上线了

    感谢大家一直以来的支持! 各大商店均开始销售:京东:http://item.jd.com/11659698.html当当:http://product.dangdang.com/23659808.ht ...

  4. 如何让R代码按计划执行

    应用场景:你编写了R代码,每天对提交的数据进行分析,你希望它你吃饭的时候执行完毕,生成图表. 那么你需要安装taskscheduleR的包. 怎么操作,看帮助呗.

  5. php面向对象的基础:创建OOP的类和字段

    类的创建 class Computer{ //类的字段(成员) //类的方法 } 对象的声明 $computer = new Computer(); new标识符是为了在内存中创建一个对象(实例),而 ...

  6. 嵌入式 linux 移植修改后的libjpeg 实现内存中解码

    1.修改libjpeg源码,使之实现内存解码. 修改libjpeg中读取或者输出jpeg文件的函数接口文件jdatadst.c和jdatasrc.c见下面这篇帖子. http://blog.163.c ...

  7. (转)文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别

    这两天在调优数据库性能的过程中需要降低操作系统文件Cache对数据库性能的影响,故调研了一些降低文件系统缓存大小的方法,其中一种是通过修改/proc/sys/vm/dirty_background_r ...

  8. 一些常用css技巧的为什么(一)我所理解的margin

    要用到的基本术语和概念: 正常流:HTML文档的文本布局,在非西方语言中流的方向可能不同.大多数元素都在正常流中,浮动或定位可以让元素脱离正常流. 块级元素:像p,div之类的元素在正常流中会在其框之 ...

  9. ListView Web 服务器控件概述(MSDN)

    1: "折叠"图像"展开"图像"复制"图像"复制悬停"图像 全部折叠全部展开 代码:全部 代码:多个 代码:Visual ...

  10. DataGridView导入导出excel

    DataGridView导出到Excel #region 方法一 DateGridView导出到csv格式的Excel /// <summary> /// 导出数据到Excel.常用方法, ...