1.简单介绍
应用程序组件,提供交互界面。
2.Activity的创建
- 继承Activity类
- 重写方法
- 显示布局
- 在AndroidManifest中注册Activity
3.生命周期
- onCreate()
- onStart()
- onResume()
- Running
- onPause()
- onStop()
- onDestroy()
4.代码实例
package com.example.activity; import android.os.Bundle; import android.util.Log; import android.app.Activity; import android.view.Menu; public class MainActivity extends Activity { final String TAG = "tag"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.i(TAG, "1"); } @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); Log.i(TAG, "2"); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); Log.i(TAG, "3"); } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); Log.i(TAG, "4"); } @Override protected void onStop() { // TODO Auto-generated method stub super.onStop(); Log.i(TAG, "5"); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); Log.i(TAG, "6"); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }