Activity的生命周期(一)
2016-02-27 05:45
197 查看
一个Activity的诞生:onCreate --> onStart --> onResume
一个Activity的销毁:onPause --> onStop --> onDestroy
一个Activity经历横竖屏旋转后:onPause --> onStop --> onDestroy --> onCreate --> onStart --> onResume
测试代码:
activity_one.xml
【Activity创建】
【Activity休眠】
【Activity唤醒】
【Activity销毁】
【Activity旋转】
那张经典的Activity生命周期图
一个Activity的销毁:onPause --> onStop --> onDestroy
一个Activity经历横竖屏旋转后:onPause --> onStop --> onDestroy --> onCreate --> onStart --> onResume
测试代码:
/** * 一、重识Activity:一个Activity的生命周期 * 从创建到销毁:三状态六节点 * 可见状态:onCreate onStart onResume * 隐藏状态:onPause onStop * 销毁状态:onDestroy * 二、横竖屏旋转Activity的生命周期 * 创建Activity: * OneActivity onCreate --> OneActivity onStart --> OneActivity onResume * * 休眠Activity: * OneActivity onPause --> OneActivity onStop * * 唤醒Activity: * OneActivity onRestart() --> OneActivity onStart --> OneActivity onResume * * 退出Activity: * OneActivity onPause --> OneActivity onStop --> OneActivity onDestroy * * 旋转Activity: * OneActivity onPause --> OneActivity onStop --> OneActivity onDestroy --> OneActivity onCreate --> OneActivity onStart --> OneActivity onResume * * @author 贾涛 * */ public class OneActivity extends Activity { private String TAG = "OneActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.e(TAG, "onCreate"); } @Override protected void onStart() { super.onStart(); Log.e(TAG, "onStart"); } @Override protected void onRestart() { super.onRestart(); Log.e(TAG, "onRestart"); } @Override protected void onResume() { super.onResume(); Log.e(TAG, "onResume"); } @Override protected void onPause() { super.onPause(); Log.e(TAG, "onPause"); } @Override protected void onStop() { super.onStop(); Log.e(TAG, "onStop"); } @Override protected void onDestroy() { super.onDestroy(); Log.e(TAG, "onDestroy"); } }
activity_one.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.imooc.activitystudy.OneActivity" > <TextView android:id="@+id/tv_actName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </RelativeLayout>
【Activity创建】
【Activity休眠】
【Activity唤醒】
【Activity销毁】
【Activity旋转】
那张经典的Activity生命周期图
相关文章推荐
- C++ DirectX 游戏开发初级视频教程 20 资源下载链接
- 38. Count and Say
- 如何解决Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386]
- HDU 1026 Ignatius and the Princess I(BFS+优先队列)
- Fedora21下安装cuda7.5
- x264源码分析与应用示例(三)——浅谈码率控制的优化问题
- 229. Majority Element II
- [POJ 1836]Alignment[DP][LIS]
- 【HTML5】基础知识
- jquery 相关知识
- c++11对多线程的典型用法
- Activity和AppCompatActivity的区别
- 尝试在非root用户下进行nginx的反向代理-1
- 个人进阶之路——自定义控件(5)
- 152. Maximum Product Subarray
- java 利用*号打印三角形
- 产品前端重构(TypeScript、MVC框架设计)
- GlobalValue
- Simulator,Scheduler和时间
- Simulator相关