一.Activity生命周期和Task
1.要看到Android生命周期的效果,必须启动Android SDK调试工具。找到Eclipse透视图:DDMSwindow-->open perspective-->DDMS配置DDMS视图(显示System.out.println()):
2.要看到输出的内容:必须加一个日志的过滤器:即可点击小加号
Filter Name:Demo
by Log Tag:Demo Activity
by Log level:选择Verbose对应Log.v
点击OK就配置好了。
可以试试System.out
必须加一个日志的过滤器:
点击小加号
Filter Name:System.out
by Log Tag:System.out
点击OK就配置好了。
/**
* 按HOME键返回应用程序界面,点击Demo进入Activity
* 依序显示Create/Start/Resume
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置标题栏
// requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
// setContentView(R.layout.main);
// this.getWindow().setFeatureInt
// (Window.FEATURE_CUSTOM_TITLE, R.layout.title);
//去除标题栏:
// requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
// this.getWindow()
// .setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
Toast.makeText
(this, this.getString(R.string.create_tag),
Toast.LENGTH_SHORT).show();
Log.v("MainActivity", "onCreate()");
}
@Override
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
Toast.makeText(this, "onSaveInstanceState", Toast.LENGTH_LONG).show();
Log.v("Activity LifeCycle", "onSaveInstanceState");
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Toast.makeText(this, "onStart", Toast.LENGTH_LONG).show();
Log.v("Activity LifeCycle", "onStart");
}
//如果在拨号界面按下返回键,则依序执行Restart/Start/Resume
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
Toast.makeText(this, "onRestart()", Toast.LENGTH_LONG).show();
Log.v("Activity LifeCycle", "onRestart()");
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Toast.makeText(this, "onResume() ", Toast.LENGTH_LONG).show();
Log.v("Activity LifeCycle", "onResume() ");
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Toast.makeText(this, "onPause() ", Toast.LENGTH_LONG).show();
Log.v("Activity LifeCycle", "onPause() ");
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Toast.makeText(this, "onStop() ", Toast.LENGTH_LONG).show();
Log.v("Activity LifeCycle", "onStop() ");
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Toast.makeText(this, "onDestroy() ", Toast.LENGTH_LONG).show();
Log.v("Activity LifeCycle", "onDestroy() ");
}
}
二.三个“栏”的处理
//设置标题栏
this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);//注意setContentView的使用时机
this.getWindow()
.setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
//去除标题栏:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
//去除状态栏:
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
this.getWindow()
.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);