Lạng Hoàng
Lạng Hoàng

Reputation: 1800

Activity lifecycle and rotate issue?

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 ------------------");
    }

Upvotes: 0

Views: 112

Answers (1)

Manish
Manish

Reputation: 1279

check your code mate...in

onDestroy()

method you call

super.onStop();  

thats why you didn't get on Destroy in your log. put

super.onDestroy(); 

inside onDestroy() method then you easily understand the activity life cycle - on orientation change.

Upvotes: 1

Related Questions