Project——Activity生命周期

来源:互联网 发布:python入门书籍推荐 编辑:程序博客网 时间:2024/06/17 16:08

1、

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="cn.itcast.life"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
  <activity android:name=".OtherActivity" />
  <activity android:name=".ThreeActivity" android:theme="@android:style/Theme.Dialog"/>
    </application>
    <uses-sdk android:minSdkVersion="8" />

</manifest>

2、

package cn.itcast.life;

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

public class MainActivity extends Activity {
    private static final String TAG = "MainActivity";
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        Button button = (Button)this.findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {   
   @Override
   public void onClick(View v) {
    Intent intent = new Intent(MainActivity.this, OtherActivity.class);
    startActivity(intent);
   }
  });
       
       
        Button button2 = (Button)this.findViewById(R.id.button2);
        button2.setOnClickListener(new View.OnClickListener() {   
   @Override
   public void onClick(View v) {
    Intent intent = new Intent(MainActivity.this, ThreeActivity.class);
    startActivity(intent);
   }
  });
     Log.i(TAG, "onCreate()");
    }

 @Override
 protected void onDestroy() {
  Log.i(TAG, "onDestroy()");
  super.onDestroy();
 }

 @Override
 protected void onPause() {
  Log.i(TAG, "onPause()");
  super.onPause();
 }

 @Override
 protected void onRestart() {
  Log.i(TAG, "onRestart()");
  super.onRestart();
 }

 @Override
 protected void onResume() {
  Log.i(TAG, "onResume()");
  super.onResume();
 }

 @Override
 protected void onStart() {
  Log.i(TAG, "onStart()");
  super.onStart();
 }

 @Override
 protected void onStop() {
  Log.i(TAG, "onStop()");
  super.onStop();
 }
   
}

3、

package cn.itcast.life;

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

public class OtherActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.other);
 }

}

4、

package cn.itcast.life;

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

public class ThreeActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.three);
 }

}

 

原创粉丝点击