Activity

Activity

一、     什么是Activity

Activity负责了一个Android应用程序的门面。可以称之为形象大使。

二、     Activity的生命周期:

protected void increate(Bundle savedInstanceState);

 

protected void onStart();

     

protected void onRestart();

 

protected void onResume();

 

protected void onPause();

 

protected void onStop();

 

protected void onDestroy();

三、     从一个Activity切换到另一个Activity:

Activity代码:

private Button btn1=null;

    @Override

    public void increate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        btn1=(Button)findViewById(R.id.btn1);

        btn1.setText(R.string.ac1);

        btn1.setOnClickListener(new MyButton());

    }

    class MyButton implements OnClickListener{

 

       public void onClick(View v) {

           Uri uri=Uri.parse("smsto://1201024");

           Intent intent=new Intent(Intent.ACTION_SENDTO,uri);

           intent.putExtra("sms_body", "你好,有空吗,我们一起吃个饭");

           startActivity(intent);

           /*

           Intent intent=new Intent();

           intent.putExtra("guoxu", "这是我的一个程序");

           intent.setClass(ActivityDemo2Activity.this, Other.class);

           ActivityDemo2Activity.this.startActivity(intent);

           */

       }

    

    }

AndroidManifest.xml代码

<?xmlversion="1.0"encoding="utf-8"?>

<manifestxmlns:android="http://schemas.android.com/apk/res/android"

      package="org.activity.demo"

      android:versionCode="1"

      android:versionName="1.0">

    <uses-sdkandroid:minSdkVersion="3"/>

 

    <application android:icon="@drawable/icon" android:label="@string/app_name">

        <activity android:name=".ActivityDemo2Activity"

                  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=".Other" android:label="@string/other">

        </activity>

 

    </application>

</manifest>

 

四、     从一个Activity中以对话框的形式弹出另一个Activity:

只需要在AndroidManifest.xml设置:

<activityandroid:name=".SecondActivity"android:label="第二个Activity"

       android:theme="@android:style/Theme.Dialog"></activity>

 

posted @ 2011-08-29 22:51  rorshach  阅读(279)  评论(0编辑  收藏  举报