欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android編程之基于Log演示一個(gè)activity生命周期實(shí)例詳解

 更新時(shí)間:2015年12月21日 11:20:53   作者:penglijiang  
這篇文章主要介紹了Android編程之基于Log演示一個(gè)activity生命周期,結(jié)合完整實(shí)例形式較為詳細(xì)的分析總結(jié)了Log演示activity生命周期的具體用法及Log的具體使用方法,需要的朋友可以參考下

本文實(shí)例講述了Android編程之基于Log演示一個(gè)activity生命周期。分享給大家供大家參考,具體如下:

利用Android的Log 演示一個(gè)activity的生命周期

代碼:

//DemoActivity.java
package uni.activity;
/*
@author octobershiner
2011 7 22
SE.HIT
*/
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class ActivityDemoActivity extends Activity {
  /** Called when the activity is first created. */
  private static final String TAG = "demo";
  @Override
  public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);
   Log.d("demo", "this is a test string ");
  }
  protected void onStart(){
   super.onStart();
   Log.i(TAG, "The activity state---->onStart");
  }
  protected void onRestart(){
   super.onRestart();
   Log.i(TAG, "The activity state---->onReatart");
  }
  protected void onResume(){
   super.onResume();
   Log.i(TAG, "The activity state---->onResume");
  }
  protected void onPause(){
   super.onPause();
   Log.i(TAG, "The activity state---->onPause");
  }
  protected void onStop(){
   super.onStop();
   Log.i(TAG, "The activity state---->onStop");
  }
  protected void onDestroy(){
   super.onDestroy();
   Log.i(TAG, "The activity state---->onDestroy");
  }
}

這是演示的結(jié)果

利用LOG展示activity的生命周期

注釋表示 中間執(zhí)行的操作 為方便的觀察數(shù)據(jù),可以在LOGCAT窗口(沒(méi)有的話可以在window菜單中的show view中調(diào)出)的右側(cè)單擊加號(hào)創(chuàng)建一個(gè)過(guò)濾器,我的例子中過(guò)濾的是demo

//開(kāi)始運(yùn)行demo 
07-22 11:18:19.311: INFO/demo(281): The activity state---->onStart
07-22 11:18:19.311: INFO/demo(281): The activity state---->onResume
//按下了back鍵 返回 activity從stack中彈出
07-22 11:18:34.821: INFO/demo(281): The activity state---->onPause
07-22 11:18:35.090: INFO/demo(281): The activity state---->onStop
07-22 11:18:35.090: INFO/demo(281): The activity state---->onDestroy
//再次啟動(dòng)demo
07-22 11:18:45.550: INFO/demo(281): The activity state---->onStart
07-22 11:18:45.550: INFO/demo(281): The activity state---->onResume
//按下了HOME鍵 當(dāng)前TASK 處于后臺(tái)轉(zhuǎn)態(tài),系統(tǒng)保存狀態(tài)
07-22 11:18:53.750: INFO/demo(281): The activity state---->onPause
07-22 11:18:54.820: INFO/demo(281): The activity state---->onStop
//再次啟動(dòng)demo 回復(fù)原來(lái)的TASK activity在棧頂
07-22 11:19:03.550: INFO/demo(281): The activity state---->onReatart
07-22 11:19:03.550: INFO/demo(281): The activity state---->onStart
07-22 11:19:03.550: INFO/demo(281): The activity state---->onResume

另外過(guò)濾查看log的方法:

實(shí)例

復(fù)制代碼 代碼如下:
Log.i("yourDemo","this is my log");

沒(méi)有LOGCAT窗口的朋友可以在window菜單中的show view中調(diào)出窗口

五個(gè)圓圈分別可以過(guò)濾五種不同的log

注意右邊的綠色加號(hào),單擊可以自定義自己的過(guò)濾器,名字隨便起就好了

by Log Tag欄目中 選擇你要?jiǎng)?chuàng)建的過(guò)濾規(guī)則,比如你要過(guò)濾出所遇TAG標(biāo)記為“yourDemo”的log,就可以在里面輸入yourDemo了

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論