Activity的生命周期(二)——简单继承父类

来源:互联网 发布:姬存希 知乎 编辑:程序博客网 时间:2024/06/02 02:13

父类代码:

/**    * @author 贾涛    * @date 2016-2-27 上午5:59:49  */public class BaseActivity extends Activity {private String TAG = "BaseActivity";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);Log.e(TAG, "onCreate");}@Overrideprotected void onStart() {super.onStart();Log.e(TAG, "onStart");}@Overrideprotected void onRestart() {super.onRestart();Log.e(TAG, "onRestart");}@Overrideprotected void onResume() {super.onResume();Log.e(TAG, "onResume");}@Overrideprotected void onPause() {super.onPause();Log.e(TAG, "onPause");}@Overrideprotected void onStop() {super.onStop();Log.e(TAG, "onStop");}@Overrideprotected void onDestroy() {super.onDestroy();Log.e(TAG, "onDestroy");}}

子类代码:

public class OneActivity extends BaseActivity {private String TAG = "OneActivity";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);Log.e(TAG, "onCreate");}@Overrideprotected void onStart() {super.onStart();Log.e(TAG, "onStart");}@Overrideprotected void onRestart() {super.onRestart();Log.e(TAG, "onRestart");}@Overrideprotected void onResume() {super.onResume();Log.e(TAG, "onResume");}@Overrideprotected void onPause() {super.onPause();Log.e(TAG, "onPause");}@Overrideprotected void onStop() {super.onStop();Log.e(TAG, "onStop");}@Overrideprotected 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旋转】


0 0