0

I'm learning about activity lifecycle. When i rotate the phone (from potrait to landscape or otherwise) i can see the activity change from resume -> pause -> stop -> create.

My question is why doen't change from resume -> pause -> stop -> restart -> start ? Any one help me to understand? pls!

The log:

D:\PROJECTS\AndroidTraining>adb logcat System.out:I *:S
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
I/System.out(21074): -------------------- ON CREATE ------------------
I/System.out(21074): -------------------- ON START ------------------
I/System.out(21074): -------------------- ON RESUME ------------------
I/System.out(21074): -------------------- ON PAUSE ------------------
I/System.out(21074): -------------------- ON STOP ------------------
I/System.out(21074): -------------------- ON CREATE ------------------
I/System.out(21074): -------------------- ON START ------------------
I/System.out(21074): -------------------- ON RESUME ------------------

And my code here:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        System.out.println("-------------------- ON CREATE ------------------");
        setContentView(R.layout.activity_main);
    }

    protected void onSaveInstanceState(Bundle savedInstanceState){
        super.onSaveInstanceState(savedInstanceState);
    }

    protected void onStart(){
        super.onStart();
        System.out.println("-------------------- ON START ------------------");
    }

    protected void onResume(){
        super.onResume();
        System.out.println("-------------------- ON RESUME ------------------");
    }

    protected void onPause(){
        super.onPause();
        System.out.println("-------------------- ON PAUSE ------------------");
    }

    protected void onStop(){
        super.onStop();
        System.out.println("-------------------- ON STOP ------------------");
    }

    protected void onRestart(){
        super.onRestart();
        System.out.println("-------------------- ON RESTART ------------------");
    }

    protected void onDetroy(){
        super.onStop();
        System.out.println("-------------------- ON DETROY ------------------");
    }
4

1 回答 1

1

检查你的代码伙伴...在

onDestroy()

你调用的方法

super.onStop();  

这就是为什么你没有进入on Destroy你的log. 放

super.onDestroy(); 

insideonDestroy()方法然后你很容易理解活动的生命周期——关于方向的改变。

于 2013-05-02T07:01:46.277 回答