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( ...
随机推荐
- 【转】DBA需要的技能
dba掌握的技术 1. os : linux,solaris或其他unix起码要一种 2. bash (不精通也要熟) LINUX与UNIX SHELL编程 ...
- 北大ACM(POJ1006-Biorhythms)
Question:http://poj.org/problem?id=1006 问题点:孙子定理 Memory: 248K Time: 0MS Language: C++ Result: Accept ...
- 20141017--类型String类
Console.Write("请输入您的身份证号"); string x=Console.ReadLine();//小string是大String的快捷方式 int i = x.L ...
- Session State Pattern会话状态模式
Client Session State 客户会话状态. 在Client端保存会话状态. 运行机制 Client在每次请求时会把所有的会话数据传给Server,Server在响应时把所有的会话状态传给 ...
- java中从1000万个随机数中查找出相同的10万个随机数花的最少时间
偶然在群里看到有人问到大数据查询,自己也就想了小艾改如何解决,从从1000万个随机数中查找出相同的10万个随机数花的最少时间, 谈到效率,自然是hashmap莫属. import java.util. ...
- [javascript|基本概念|Number]学习笔记
Number类型的值:整数/浮点数值 整数 十进制 e.g.: var intNum = 50; 八进制 (严格模式下无效,解析错误)字面值首位必须是0,之后的数字序列为0-7 e.g.: va ...
- maven 练习
新建项目: Next next next 新建项目后,MyEclipse会自动从远程仓库中下载支持包,需要几分钟左右时间. 项目结构图: HelloWorld.java public class He ...
- Makefile 基本知识
Technorati 标签: Makefile 基本知识 最常见的书写方式: CC = gcc LD = ld STRIP = strip CFLAGS := -Os -static -DEZ_O ...
- BootstrapDialog自动加<br> BUG处理
用惯了其他的ui框架 ,综合感觉BootstrapDialog算是最好的一个了. 因为不想在js中写过多的html代码,所以习惯的写法,把代码写在html中,js引用 实例如下: html代码 < ...
- Linux C 程序 GTK+图形界面编程(22)
GTK+图形界面编程 Linux大多是在字符界面,但也可以开发图形界面 目前已经存在多种Linux下开发图形界面的程序开发包:最常用的是Qt和GTK+ Qt是一个跨平台的图形界面开发库,不仅仅支持Li ...