android学习笔记07(activity跳转,通信,及发短信)

MyActivity02.java类:

package tk.myactivity02;



import android.net.Uri; 

import android.os.Bundle; 

import android.app.Activity; 

import android.content.Intent; 

import android.view.Menu; 

import android.view.View; 

import android.view.View.OnClickListener; 

import android.widget.Button;



public class MyActivity02 extends Activity { 

    

    private Button myButton = null; 

    

    @Override 

    public void onCreate(Bundle savedInstanceState) { 

        super.onCreate(savedInstanceState); 

        setContentView(R.layout.activity_my_activity02); 

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

        myButton.setOnClickListener(new MyButtonListener()); 

    } 

    class MyButtonListener implements OnClickListener{ 

        

        public void onClick(View v) { 

            Intent intent=new Intent(); 

            intent.putExtra("testIntent", "发送"); 

               intent.setClass(MyActivity02.this,OtherActivity02.class ); 

            MyActivity02.this.startActivity(intent); 

            

        } 

        

        

    

    }



    @Override 

    public boolean onCreateOptionsMenu(Menu menu) { 

        getMenuInflater().inflate(R.menu.activity_my_activity02, menu); 

        return true; 

    } 

}

OtherActivity02.java类:

package tk.myactivity02;



import android.app.Activity; 

import android.content.Intent; 

import android.net.Uri; 

import android.os.Bundle; 

import android.view.Menu; 

import android.view.View; 

import android.view.View.OnClickListener; 

import android.widget.TextView;



public class OtherActivity02 extends Activity{ 

    private TextView myTextView=null; 

    @Override 

    protected void onCreate(Bundle savedInstanceState) { 

        // TODO Auto-generated method stub 

        super.onCreate(savedInstanceState); 

        setContentView(R.layout.other02); 

        Intent intent=getIntent(); 

        String value=intent.getStringExtra("testIntent"); 

        myTextView=(TextView)findViewById(R.id.myTextView); 

        myTextView.setText(value); 

        myTextView.setOnClickListener(new MyButtonListener()); 

        

    } 

    class MyButtonListener implements OnClickListener{ 

        

        public void onClick(View v) { 

            //发短息 

            Uri uri=Uri.parse("smsto:18744047602"); 

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

            intent.putExtra("sms_body","The SMS text"); 

            startActivity(intent); 

        }



    } 

    

    @Override 

    public boolean onCreateOptionsMenu(Menu menu) { 

        getMenuInflater().inflate(R.menu.activity_my_activity02, menu); 

        return true; 

    } 

    

}

activity_my_activity02.xml文件:

<?xml version="1.0" encoding="utf-8"?> 

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

    android:orientation="vertical" 

    android:layout_width="fill_parent" 

    android:layout_height="fill_parent" 

    >



<Button 

    android:id="@ id/myButton" 

    android:layout_width="fill_parent" 

    android:layout_height="wrap_content" 

    />





</LinearLayout>

 

other02.xml文件:

<?xml version="1.0" encoding="utf-8"?> 

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

    android:orientation="vertical" 

    android:layout_width="fill_parent" 

    android:layout_height="fill_parent" 

    > 

<TextView 

    android:id="@ id/myTextView" 

    android:layout_width="fill_parent" 

    android:layout_height="wrap_content" 

    />



</LinearLayout>

manifest.xml文件配置:

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

    package="tk.myactivity02" 

    android:versionCode="1" 

    android:versionName="1.0" >



    <uses-sdk 

        android:minSdkVersion="8" 

        android:targetSdkVersion="15" />



    <application 

        android:icon="@drawable/ic_launcher" 

        android:label="@string/app_name" 

        android:theme="@style/AppTheme" > 

        <activity 

            android:name=".MyActivity02" 

            android:label="@string/title_activity_my_activity02" > 

            <intent-filter> 

                <action android:name="android.intent.action.MAIN" />



                <category android:name="android.intent.category.LAUNCHER" /> 

            </intent-filter> 

        </activity> 

        <activity 

            android:name=".OtherActivity02" 

            android:label="@string/other" 

            > 

        

        </activity> 

        

        

    </application>



</manifest>

你可能感兴趣的:(Android学习)