目录
4.上述步骤完成应该如下第一张图,在logcat输入行中输入tag:TAG,输入后运行程序;通过虚拟手机对自己的应用程序关闭打开等操作,观察数据;
1.新建安卓工程
2.将MainActivity类设置如下代码
package com.example.cc;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.Window;
public class MainActivity extends Activity {
private final String tag = "TAG";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main); //设置一个View模板
Log.d(tag, "In the onCreate() event");
}
@Override
public void onStart() {
super.onStart();
Log.d(tag, "In the onStart() event");
}
public void onRestart() {
super.onRestart();
Log.d(tag, "In the onRestart() event");
}
public void onResume() {
super.onResume();
Log.d(tag, "In the onResume() event");
}
public void onPause() {
super.onPause();
Log.d(tag, "In the onPause() event");
}
public void onStop() {
super.onStop();
Log.d(tag, "In the onStop() event");
}
public void onDestroy() {
super.onDestroy();
Log.d(tag, "1111In the onDestroy() event");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
package com.example.cc;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.Window;
public class MainActivity extends Activity {
private final String tag = "TAG";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main); //设置一个View模板
Log.d(tag, "In the onCreate() event");
}
@Override
public void onStart() {
super.onStart();
Log.d(tag, "In the onStart() event");
}
public void onRestart() {
super.onRestart();
Log.d(tag, "In the onRestart() event");
}
public void onResume() {
super.onResume();
Log.d(tag, "In the onResume() event");
}
public void onPause() {
super.onPause();
Log.d(tag, "In the onPause() event");
}
public void onStop() {
super.onStop();
Log.d(tag, "In the onStop() event");
}
public void onDestroy() {
super.onDestroy();
Log.d(tag, "1111In the onDestroy() event");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
3.打开ddms工具,并且打开logcat;
打开DDMS(如上图)
打开Logcat如上图
4.上述步骤完成应该如下第一张图,在logcat输入行中输入tag:TAG,输入后运行程序;通过虚拟手机对自己的应用程序关闭打开等操作,观察数据;![](https://i-blog.csdnimg.cn/blog_migrate/f85927500dd19c80df3d16f42108476a.png)
5.输入成功,大概如下。可能显示的信息不同;