码迷,mamicode.com
首页 > 其他好文 > 详细

Activity生命周期

时间:2015-05-04 20:19:45      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:android开发

Activity生命周期

Activity 生命周期 android Markdown

Activity的开启

activity首次启动:执行顺序onCreate——>onStart——>onResume

截图

技术分享

package com.river.activitylife;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.i("life", "MainActivity onCreate");
    }

    public void loadSecond(View view) {
        startActivity(new Intent(this, SecondActivity.class));
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        Log.i("life", "MainActivity onDestroy");
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        Log.i("life", "MainActivity onResume");
    }

    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
        Log.i("life", "MainActivity onStart");
    }

    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
        Log.i("life", "MainActivity onStop");
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        Log.i("life", "MainActivity onPause");
    }

    @Override
    protected void onRestart() {
        // TODO Auto-generated method stub
        super.onRestart();
        Log.i("life", "MainActivity onRestart");
    }

}

Activity结束(按返回键)

activity结束:执行顺序:自身onPause——>自身onStop——>自身onDestroy

截图

技术分享


Activity跳转到其他Activity

activity跳转到其他Activity:执行顺序:自身onPause——>其他onCreate——>其他

截图

技术分享

package com.river.activitylife;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class SecondActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        Log.i("life", "SecondActivity onCreate");
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        Log.i("life", "SecondActivity onDestroy");
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        Log.i("life", "SecondActivity onPause");
    }

    @Override
    protected void onRestart() {
        // TODO Auto-generated method stub
        super.onRestart();
        Log.i("life", "SecondActivity onRestart");
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        Log.i("life", "SecondActivity onResume");
    }

    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
        Log.i("life", "SecondActivity onStart");
    }

    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
        Log.i("life", "SecondActivity onStop");
    }

}

Activity跳转到主Activity

activity跳转到主Activity:执行顺序:最好看图 

截图

技术分享

Activity生命周期

标签:android开发

原文地址:http://blog.csdn.net/c_major/article/details/45483785

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!