android Activity类中的finish()、onDestory()和System.exit(0) 三者的区别
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) 三者的区别的更多相关文章
- 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 ...
- Android:finish()与System.exit(0)之间的区别
finish()与System.exit(0)都是用来退出.但是两者还是有一定的区别: finish是Activity的类,仅仅针对Activity,当调用finish()时,只是将活动推向后台,并没 ...
- android Process.killProcess 和 System.exit(0) 区别
1 Process.killProcess 和 System.exit(0) 两个都会 kill 掉当前进程. 你可以打开 DDMS 查看进程号,或 adb shell 进入 shell 然后 ps ...
- android开发中关于继承activity类中方法的调用
android开发中关于继承activity类中的函数,不能在其他类中调用其方法. MainActivity.java package com.example.testmain; import and ...
- 安卓开发-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开发时,finish()跟System.exit(0)的区别
这两天在弄Android,遇到一个问题:所开发的小游戏中有背景音乐,玩的过程中始终有音乐在放着,然后在我退出游戏后,音乐还在播放! 我看了一下我最开始写的退出游戏的代码,就是简单的finish() ...
- android finish和system.exit(0)的区别
finish是Activity的类,仅仅针对Activity,当调用finish()时,只是将活动推向后台,并没有立即释放内存,活动的资源并没有被清理:当调用System.exit(0)时,杀死了整个 ...
- android中 System.exit(0)的理解
public class HelloGoodbye{ try{ System.out.println(“Hello World”); System.exit(0); } finally { Syste ...
随机推荐
- Ajax请求数据
后台使用数数组的形式存放数据(以键值对的形式存放).让后再Json转码. Map<String,String> map=new HashMap<String,String>() ...
- Spring异常抛出触发事务回滚
Spring.EJB的声明式事务默认情况下都是在抛出unchecked exception后才会触发事务的回滚 /** * 如果在spring事务配置中不为切入点(如这里的切入点可以定义成test*) ...
- Maven的包依赖冲突可引发java.lang.IncompatibleClassChangeError错误
新版API上线后,发现LOG文件没有正常输出.查看Tomcat的Log文件发现如下的错误信息 May , :: AM com.sun.xml.ws.server.sei.EndpointMethodH ...
- faster-rcnn(testing): ubuntu14.04+caffe+cuda7.5+cudnn5.1.3+opencv3.0+matlabR2014a环境搭建记录
python版本的faster-rcnn见我的另一篇博客: py-faster-rcnn(running the demo): ubuntu14.04+caffe+cuda7.5+cudnn5.1.3 ...
- Generate SQL from Excel
Tips: SUBSTITUTE(D4,"'","''")---if D4 contain ', this function will convert ' ...
- HTTPS 和 HTTP
https://www.zhihu.com/question/52790301
- 转: python如何安装pip和easy_installer工具
原文地址: http://blog.chinaunix.net/uid-12014716-id-3859827.html 1.在以下地址下载最新的PIP安装文件:http://pypi.python. ...
- Getting Started
https://developers.google.com/v8/get_started Getting Started This document introduces some key V8 co ...
- linux 驱动学习笔记04--简单驱动
首先贴代码helloworld.c和Makefile /************************************************************************ ...
- DWT小波变换及其在时间序列数据预测中的应用
Given data: 时间序列数据. Goal:做预测 方法:在滑动窗口中取DWT特征,并验证. 实验验证: Load forcast 数据集. 问题: 小波变换的物理意义是什么? 小波变换的数学意 ...