下面就是小编整理的活动(activity)的生命周期(共含7篇),希望大家喜欢。同时,但愿您也能像本文投稿人“颗粒”一样,积极向本站投稿分享好文章。
一、周期的各个阶段
首先,通过谷歌官方发布的生命周期图来理解一下整个流程:
首先在这里简要介绍一下周期中各个方法:<?www.2cto.com/kf/ware/vc/“ target=”_blank“ class=”keylink“>vcD4NCgk8cD5vbkNyZWF0ZSgpOtTau+62r7G7tLS9qLXEyrG68ta00NA8YnIgLz4NCglvblN0YXJ0KCk61Nq77ravv6rKvL/JvPu1xMqxuvLWtNDQPGJyIC8+DQoJb25QYXVzZSgpOtTau+62r8qnyKW9ubXjo6yyu7/Jvbu7pbXEyrG68ta00NCjrLWrtMvKsbTLu+62r8jUyLu/ybz7PGJyIC8+DQoJb25TdG9wKCk61Nq77ravzerIq7G7xuTL+7vutq+4srjHtcTKsbry1rTQ0KOsz9TIu6OstMvKsbvutq+yu7/JvPvByzxiciAvPg0KCW9uRGVzdG9yeSgpOtTau+62r8/6u9m1xMqxuvI8YnIgLz4NCglvblJlc3RhcnQoKTq1sbG7uLK4x7XEu+62r8O7sbu72MrV1Nm0zsb0tq+1xMqxuvK199PDoaM8L3A+DQo8L2Jsb2NrcXVvdGU+DQo8aDMgaWQ9”二用三个小周期去理解整个生命周期“>二、用三个小周期去理解整个生命周期
从onCreate到onDestroy()之间所经历的的是完整的生命周期,所以,应该在onCreate()完成各种初始化操作,在onDestroy()完成各种资源回收的操作。
从onStart()到onStop()之间所经历的的是可见生命周期,只要是在这之间,activity的内容都是可见的。既然是从onStart()开始可见,到onStop()不可见,那么我们就可以在onStart()里边加载用户可见的资源,在onStop()里边释放这些资源。这样的话,比在onDestroy()里边释放资源要节省内存。
从onResume()到onPause()之间经历的是前台生命周期,在这之间的不仅可见,而且是可以交互的。
三、各个方法执行的时机
这个不用多说啦,就是在Activity被创建的时候调用。如果一个Activity被回收掉,那么他再次启动的时候也会调用这个方法。
Activity被创建以后,便开始启动,执行了onStart()方法以后,这个Activity便可见。如果一个Activity被完全覆盖但是系统没有回收它,那么他再次启动的时候,便会先执行onRestart()方法,然后再次执行onStart()方法,
右上边的图片可以看出
查了一下单词“Resume”的意思是恢复的意思。实在搞不明白恢复放在这里的关系。但是onResume()执行完以后,这个Activity便可以与用户进行交互了。这个Activity便处于正式的运行状态,可以与用户进行交互。
当另外一个活动来到前台的时候,此时要将当前运行的Activity覆盖,会先执行这个方法,然后在执行onStop()。不过,如果到来的是一个对话框(没有完全覆盖当前Activity)的话,当前的Activity便会执行到onPause(),不会继续执行inStop(),因为他并不是完全不可见的。此时,在这个状态下,除非是内存极其紧张,否则不会回收这个Activity。
如果当前activity被另一个Activity覆盖了,完全不可见了。那么onStop()便会被执行。如果内存紧张的时候,便会回收掉这个Activity。如果回收的话便会向下执行到onDestroy().
如果被完全覆盖的activity没有被回收,那么他再次执行的时候便会首先执行onRestart()方法。在执行onStart()方法。
当系统内存不足了,那么他便会首先搜寻被完全覆盖的Activity,将他们的内存释放掉,释放的时候便会执行onDestroy()方法。我们可以在onDestroy()中释放一些自己定义的变量。
四、活动被回收了怎么办
对于一般的活动,当被系统回收掉以后,无非就是重新创建这个活动。但是如果一个活动我们要求他再次创建的时候保持原样,就比如我们在文本框里输入了一些内容。那么此时该怎么办呢?
自然是有办法解决的:
onSaveInstanceState(Bundle bundle){}
这个方法会保证在活动被回收前被调用,因此我们就可以在这个方法之中做一些保存操作。然后onCreate()接受的参数就是这个方法保存的那个Bundle。
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }
activity常见的搭配
activity可以与以下词性连用:
名词,如:level of activity 活动水平
形容词,如:criminal activity 犯罪活动;physical activity 体育活动;extra-curricular activity 课外活动
例句:
We love outdoor activity.
我们热爱户外活动。
His level of activity will be low.
他的活动力水平就会很低。
The volcano is in activity.
这火山正活跃著。
Android 横竖屏切换的Activity生命周期,很多公司和企业面试会问到横竖屏切换的Activity生命周期、Handler机制、单例模式
等,不过这几个是常问的,这篇博客主要说说横竖屏切换时Activity的生命周期
① 创建一个Activity,分别标注测试语句
package” import=“import” log.dtag=“Log.d(Tag,” name=“code” oncreate=“onCreate” oncreatebundle=“onCreate(Bundle” ondestroy=“onDestroy()” onpause=“onPause()” onrestoreinstancestate=“onRestoreInstanceState()” onrestoreinstancestatebundle=“onRestoreInstanceState(Bundle” onresume=“onResume()” onsaveinstancestate=“onSaveInstanceState()” onsaveinstancestatebundle=“onSaveInstanceState(Bundle” onstart=“onStart()” onstop=“onStop()” outstate=“outState)” override=“@Override” pre=“pre” private=“private” protected=“protected” savedinstancestate=“savedInstanceState)” setcontentviewr.layout.activity_main=“setContentView(R.layout.activity_main);” static=“static” string=“String” super.oncreatesavedinstancestate=“super.onCreate(savedInstanceState);” super.ondestroy=“super.onDestroy();” super.onpause=“super.onPause();” super.onrestoreinstancestatesavedinstancestate=“super.onRestoreInstanceState(savedInstanceState);” super.onresume=“super.onResume();” super.onsaveinstancestateoutstate=“super.onSaveInstanceState(outState);” super.onstart=“super.onStart();” super.onstop=“super.onStop();” tag=“EngineerJspActivity” void=“void” 横竖屏切换activity生命周期=“横竖屏切换Activity生命周期”>
②运行Activity(没有切换屏幕的正常情况下启动Activity),得到如下结果:
③切换成横屏时的Activity生命周期:<?www.2cto.com/kf/ware/vc/“ target=”_blank“ class=”keylink“>vc3Ryb25nPjwvcD4KPHA+PHN0cm9uZz48aW1nIHNyYz0=”www.2cto.com/uploadfile/Collfiles/1106/20141106081350160.png“ alt=”\“>
④换回竖屏的Activity生命周期:
⑤给清单文件加上android:configChanges=”orientation“属性,重新启动Activity,没有切换屏幕时(正常启动)的生命周期:
⑥加上android:configChanges=”orientation“属性,切换成横屏,Activity的生命周期:
⑦加上android:configChanges=”orientation“属性,换回竖屏,Activity的生命周期:
⑧加上android:configChanges=”orientation|keyboardHidden“属性,正常启动Activity的生命周期(未切屏幕):
⑨加上android:configChanges=”orientation|keyboardHidden“属性,正常启动Activity的生命周期(切成横屏):
⑩加上android:configChanges=”orientation|keyboardHidden"属性,正常启动Activity的生命周期(换回竖屏):
执行Home键之后的生命周期:
本人是拿平板测试的,结果如有出入,跟真实结果无关,谢谢~
生命周期评价
生命周期评价是一种评价产品、工艺过程或活动从原材料的采集和加工到生产、运输、销售、使用、回收、养护、循环利用和最终处理整个生命周期系统有关的环境负荷的'过程.生命周期评价既可以作为评价产品生产全过程的有效手段,又可以作为一种环境管理工具,现已在国际上广泛应用.文章从生命周期评价的概念入手,介绍了生命周期评价产生背景、技术框架、评价方法、应用及其展望.
作 者:樊庆锌 敖红光 孟超 Fan Qingxin Ao Hongguang Meng Chao 作者单位:樊庆锌,敖红光,Fan Qingxin,Ao Hongguang(哈尔滨工业大学,市政环境工程学院,黑龙江,哈尔滨,150001)孟超,Meng Chao(黑龙江省环境保护科学研究院,黑龙江,哈尔滨,150056)
刊 名:环境科学与管理 英文刊名:ENVIRONMENTAL SCIENCE AND MANAGEMENT 年,卷(期): 32(6) 分类号:X820.3 关键词:生命周期评价 环境管理 全过程办公英语:活动安排 Activity Arrangement
Dear Mr. / Ms,We are very pleased to welcome President William Taylor and Manager James Rogers to Beijing and Shanghai in thesecond half of April for about a week. As requested,
we propose the following itinerary for your consideration.
Monday, April 18
4:00 p.m. Arrive in Beijing by Flt.xx, to be met at the airport by Mr. President of Asia Trading Co.
4:15 Leave for Great Wall Hotel
7:30 Dinner given by President x
Tuesday, April 19
9:30 a.m. Discussion at Asia Trading Co. Building
2:00 p.m. Group discussion
8:00 p.m. Cocktail reception given by the British Commercial Counselor in Beijing
Wednesday, April 20
9:00 a.m. Discussion
12:00 noon Sign the Letter of Intent
1:30 p.m. Peking Duck Dinner
3:30 p.m. visit the Summer palace
6:00 Departure for Shanghai
Would you please confirm by fax so that we can make arrangements accordingly.
Yours faithfully
尊敬的.先生/小姐,
我们非常高兴威廉・泰勒总裁和珍姆斯・罗杰斯经理能于四月下半月到北京,上海访问一周,根据要求我们提出下列活动安排供参考:
星期一,四月十八日
下午4:00 乘航班XX到达北京,由亚洲贸易公司的总裁X先生到机场迎接
4:15 乘车去长城宾馆
7:30 总裁X先生举行晚晏
上午9:30 a.m. 在亚洲贸易公司讨论
2:00 p.m. 小组讨论
8:00 p.m. 英国住北京商务领事举行鸡尾酒招待会
上午9:00 讨论
中午12:00 签订意向书
下午1:30 吃北京烤鸭
3:30 参观故宫&nbs
Research of the Activity of Earthquakes Induced by Water Injection of Salt Mining in Changning County, Sichuan Province
According to information from on-the-spot investigations, the tectonics of salt mining areas and digital seismic records, we studied the activity of earthquakes induced by water pumping in and out of the salt mines in Shuanghe town, Changning county, Sichuan Province. The study found that the rates of water injection and extraction in the Shuanghe salt mining region were evenly matched before April 2006 and earthquake activity was stable. On the other hand, shallow small and moderate earthquake numbers increased sharply after the water injection rate became much larger than the water extraction rate. Large injection over a long time may causes the permeation of water through pre-existing small fractures and micro-cracks in the Changning anticlinal and accelerate the rupture of micro tectonic formations in nearby regions, inducing small earthquake swarm activity. The Q value calculated by using digital earthquake records indicates a relatively inhomogeneous medium in this area. The results of the accurate location of small earthquakes show that sources are relatively shallow and are concentrated at a depth of 2km to 3km. Focal mechanism solutions reveal a normal dip-slip character of shallow earthquakes. All of these show certain characteristics of earthquake activity induced by water injection.
作 者:Ruan Xiang Cheng Wanzheng Zhang Yongjiu Li Jun Chen Yin 作者单位:Earthquake Administration of Sichuan Province, Chengdu 610041, China 刊 名:中国地震研究(英文版) 英文刊名:EARTHQUAKE RESEARCH IN CHINA 年,卷(期):2009 23(2) 分类号:P3 关键词:Induced earthquake Water injection of salt mining Changning county,Sichuan Province★ Android Activity intentflilter过滤机制
★ 党小组活动
★ 活动发言稿
★ 活动策划书
★ 活动策划案