asfman
android developer
posts - 90,  comments - 213,  trackbacks - 0
package com.asfman;

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

public class AndroidLifeCycle extends Activity {

    
public void onCreate(Bundle savedInstanceState) {
        Log.i(
"info""First Activity =======onCreate()========");

        
super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button btn 
= (Button) findViewById(R.id.button1);
        btn.setOnClickListener(
new OnClickListener() {

            @Override
            
public void onClick(View v) {
                Intent intent 
= new Intent();
                intent.setClass(AndroidLifeCycle.
this, Second.class);
                startActivity(intent);
                
//AndroidLifeCycle.this.finish(); //trigger onDestroy
            }

        }
);
    }


    
// Called after onCreate — or after onRestart when the activity had been
    
// stopped, but is now again being displayed to the user. It will be
    
// followed by onResume
    protected void onStart() {
        Log.i(
"info""First Activity =======onStart()========");
        
super.onStart();
    }


    
// Called after onRestoreInstanceState, onRestart, or onPause, for your
    
// activity to start interacting with the user
    protected void onResume() {
        Log.i(
"info""First Activity =======onResume()========");
        
super.onResume();
    }


    
// Called as part of the activity lifecycle when an activity is going into
    
// the background, but has not (yet) been killed
    protected void onPause() {
        Log.i(
"info""First Activity =======onPause()========");
        
super.onPause();
    }


    
// Called when you are no longer visible to the user. You will next receive
    
// either onRestart, onDestroy, or nothing, depending on later user
    
// activity.
    protected void onStop() {
        Log.i(
"info""First Activity =======onStop()========");
        
super.onStop();
    }


    
// Perform any final cleanup before an activity is destroyed
    protected void onDestroy() {
        Log.i(
"info""First Activity =======onDestroy()========");
        
super.onDestroy();
    }


    
// Called after onStop when the current activity is being re-displayed to
    
// the user (the user has navigated back to it). It will be followed by
    
// onStart and then onResume
    protected void onRestart() {
        Log.i(
"info""First Activity =======onRestart()========");
        
super.onRestart();
    }


}


package com.asfman;

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

public class Second extends Activity {

    @Override
    
protected void onCreate(Bundle savedInstanceState) {
        
// TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main1);
        Log.i(
"info""Second Activity =======onCreate()========");
    }


    
// Called after onCreate — or after onRestart when the activity had been
    
// stopped, but is now again being displayed to the user. It will be
    
// followed by onResume
    protected void onStart() {
        Log.i(
"info""Second Activity =======onStart()========");
        
super.onStart();
    }


    
// Called after onRestoreInstanceState, onRestart, or onPause, for your
    
// activity to start interacting with the user
    protected void onResume() {
        Log.i(
"info""Second Activity =======onResume()========");
        
super.onResume();
    }


    
// Called as part of the activity lifecycle when an activity is going into
    
// the background, but has not (yet) been killed
    protected void onPause() {
        Log.i(
"info""Second Activity =======onPause()========");
        
super.onPause();
    }


    
// Called when you are no longer visible to the user. You will next receive
    
// either onRestart, onDestroy, or nothing, depending on later user
    
// activity.
    protected void onStop() {
        Log.i(
"info""Second Activity =======onStop()========");
        
super.onStop();
    }


    
// Perform any final cleanup before an activity is destroyed
    protected void onDestroy() {
        Log.i(
"info""Second Activity =======onDestroy()========");
        
super.onDestroy();
    }


    
// Called after onStop when the current activity is being re-displayed to
    
// the user (the user has navigated back to it). It will be followed by
    
// onStart and then onResume
    protected void onRestart() {
        Log.i(
"info""Second Activity =======onRestart()========");
        
super.onRestart();
    }


}



Active/Runing一个新 Activity 启动入栈后,它在屏幕最前端,处于栈的最顶端,此时它处于可见并可和用户交互的激活状态.
Paused 当 Activity 被另一个透明或者 Dialog 样式的 Activity 覆盖时的状态.此时它依然与窗口管理器保持连接,系统继续维护其内部状态,所以它仍然可见,但它已经失去了焦点故不可与用户交互.
Stoped 当 Activity 被另外一个 Activity 覆盖、失去焦点并不可见时处于 Stoped状态.
Killed Activity 被系统杀死回收或者没有被启动时处于 Killed状态.
posted on 2011-03-31 17:40 汪杰 阅读(512) 评论(3)  编辑 收藏 引用 所属分类: Java

FeedBack:
# re: Android生命周期的学习
2011-04-02 15:42 | 汪杰
I/info ( 378): Application start

I/info ( 324): First Activity =======onCreate()========
I/info ( 324): First Activity =======onStart()========
I/info ( 324): First Activity =======onResume()========
I/ActivityManager( 60): Starting activity: Intent { cmp=com.asfman/.Second }
I/info ( 324): First Activity =======onPause()========
I/info ( 324): Second Activity =======onCreate()========
I/info ( 324): Second Activity =======onStart()========
I/info ( 324): Second Activity =======onResume()========
I/ActivityManager( 60): Displayed activity com.asfman/.Second: 394 ms (total 394 ms)
I/info ( 324): First Activity =======onStop()========  回复  更多评论
  
# re: Android生命周期的学习
2011-04-02 16:02 | 汪杰
package com.asfman;

import android.app.Application;
import android.util.Log;

public class Application_Entry extends Application {

@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Log.i("info", "Application start");
}

@Override
public void onTerminate() {
// TODO Auto-generated method stub
super.onTerminate();
Log.i("info", "Application terminate");
}

}
  回复  更多评论
  
# re: Android生命周期的学习
2011-04-08 21:35 | 汪杰
执行顺序
root@asfman:/home/asfman/workspace# adb logcat -s info:d
I/info (16212): Application start
I/info (16212): First Activity =======onCreate()========
I/info (16212): First Activity =======onStart()========
I/info (16212): First Activity =======onResume()========

second activity start
I/info (16212): First Activity =======onPause()========
I/info (16212): Second Activity =======onCreate()========
I/info (16212): Second Activity =======onStart()========
I/info (16212): Second Activity =======onResume()========
I/info (16212): First Activity =======onStop()========

click back button:
I/info (16212): Second Activity =======onPause()========
I/info (16212): First Activity =======onRestart()========
I/info (16212): First Activity =======onStart()========
I/info (16212): First Activity =======onResume()========
I/info (16212): Second Activity =======onStop()========
I/info (16212): Second Activity =======onDestroy()========  回复  更多评论
  
只有注册用户登录后才能发表评论。

<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(15)

随笔分类(1)

随笔档案(90)

文章分类(727)

文章档案(712)

相册

收藏夹

http://blog.csdn.net/prodigynonsense

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 456697
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜