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

Activity.finish()

Call this when your activity is done and should be closed.

在你的activity动作完成的时候,或者Activity需要关闭的时候,调用此方法。

当你调用此方法的时候,系统只是将最上面的Activity移出了栈,并没有及时的调用onDestory()方法,其占用的资源也没有被及时释放。因为移出了栈,所以当你点击手机上面的“back”按键的时候,也不会找到这个Activity。

Activity.onDestory()

the system is temporarily destroying this instance of the activity to save space.

系统销毁了这个Activity的实例在内存中占据的空间。

在Activity的生命周期中,onDestory()方法是他生命的最后一步,资源空间什么的都没有咯~~。当重新进入此Activity的时候,必须重新创建,执行onCreate()方法。

System.exit(0)

这玩意是退出整个应用程序的,是针对整个Application的。将整个进程直接KO掉。

写在最后

在自己做的项目中,根据需要使用的时候finish()方法。只有三个页面,它们之间的跳转情况如下:

主页面 < -- > 登录页  < -- > 注册页

其中注册页面中的一个按钮是“使用已有帐号登录”,事件是回到上一个Activity进行登录。当我对这个按钮不停的测试几次之后,按“back”键的时候,很遗憾,并不是按照理想的顺序:主页面 < --  登录页  < --  注册页

而是刚刚测试时候的逆向顺序:登录页  < -- > 注册页 跳完几个循环之后,才回到主页面。想想也是,Activity不停的产生,不停的塞到那个栈里面,一个一个的向外面拿,当然是这样的顺序啦。

这里面Activity页面跳转动作事件完全是通过startActivity(new Intent(.....))来实现的。经过一些资料的查找,重新认识了上面的几个方法,根据此处的实际情况和需要,选择调用当前Activity对象的finish()方法。

android Activity类中的finish()、onDestory()和System.exit(0) 三者的区别的更多相关文章

  1. 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 ...

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

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

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

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

  4. android开发中关于继承activity类中方法的调用

    android开发中关于继承activity类中的函数,不能在其他类中调用其方法. MainActivity.java package com.example.testmain; import and ...

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

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

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

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

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

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

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

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

  9. android中 System.exit(0)的理解

    public class HelloGoodbye{ try{ System.out.println(“Hello World”); System.exit(0); } finally { Syste ...

随机推荐

  1. ubuntu下 too many file open 异常

    后台高并发或者多线程的情况下,无论是操作数据库还是操作文件,应用报出 too many file open 异常,其原因是受宿主系统文件数的限制.问题解决方式如下: 第一步:检查所在系统的文件数限制 ...

  2. 启动hadoop,没有启动namenode进程。log4j:ERROR setFile(null,true) call faild.

    启动hadoop,没有启动namenode进程.log4j:ERROR setFile(null,true) call faild.   解决办法: cd /home/hadoop/hadoop-en ...

  3. PHPCMS V9 分页类的修改教程

    首先,打开 phpcms\libs\functions\global.func.php 这个文件,找到文件第622行的分页函数,复制一下,粘贴到默认分页函数的下面,重新命名后保存.(笔者在此命名为:p ...

  4. My97DatePicker 日期控制,开始时间不能>结束时间,结束时间不能<开始时间

    <li>日期: <input type="text" style="margin-top: 5px;" value="${begin ...

  5. MAC安装M2Crypto报command 'cc' failed with exit status 1

    出错分析主要是因为由于OSX升级之后 /usr/include 没有了,使用命令修改swig寻址路径: sudo env LDFLAGS="-L$(brew --prefix openssl ...

  6. HP_UX HBA 卡信息收集脚本

    #/usr/bin/shname1=`hostname`_fcioscan -kfnNC fc |grep "/dev/" >/tmp/data/$name1.txtnum1 ...

  7. [ASP.NET]

    public static int iA; protected void Button1_Click(object sender, EventArgs e) { //Label1.Text Respo ...

  8. 15.6.6 Configuring Thread Concurrency for InnoDB

    innodb_thread_concurrency 设置inndb线程个数,如果超过则休眠一段时间,时间根据 innodb_thread_sleep_delay 单位为微妙,然后放进队列. innod ...

  9. 转载:java程序打包成jar 配置文件信息路径

    一个普通的java project,里面引用了config.properties配置文件,将项目打成Runnable jar,然后将config.properties放到打包后的jar路径下,执行该j ...

  10. php+MySQL+Ajax

    点赞功能原理.     图片. 1.connect.php文件 <?php $host="localhost"; $db_user="root"; $db ...