PendingIntent - 3支apk範例public class A1 extends Activity {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        OnClickListener mListener = new OnClickListener() {            public void onClick(View v) {                Intent intent = new Intent("com.action.a3");                intent.putExtra("Data", "Information from 設計裝潢PendingIntent");                PendingIntent mPendingIntent = PendingIntent.getActivity(                        A1.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);                Intent intent2 = new Intent("com.action.a2");                intent2.putExtra("Data", "Information from A1");                // 因為PendingIntent類別有implements Parcelable,                // 所以網路行銷可以直接用puxExtra傳遞                intent2.putExtra("myPendingIntent", mPendingIntent);                startActivity(intent2);            }        };        Button mButton = (Button) findViewById(R.id.Button01);        mButton.setOnClickListener(mListener);    }}AndroidManifest.xml如下<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.a1" android:versionCode="1" 房屋出租android:versionName="1.0">    <application android:icon="@drawable/icon" android:label="@string/app_name">        <activity android:name=".A1" android:label="@string/app_name">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        買房子</activity>    </application></manifest>public class A2 extends Activity {    public Intent mIntent;    public PendingIntent mPendingIntent;    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        mIntent = getIntent();        TextView txt = (TextView) findViewById(R.id.txt1);        txt.setText(mIntent.getStringExtra("Data"));        mPendingIntent = 借貸mIntent.getParcelableExtra("myPendingIntent");        OnClickListener mListener = new OnClickListener() {            public void onClick(View v) {                if (mPendingIntent != null) {                    try {                        mPendingIntent.send();                    } catch (CanceledException e) {                    買屋    e.printStackTrace();                    }                }            }        };        Button mButton = (Button) findViewById(R.id.Button01);        mButton.setOnClickListener(mListener);    }}AndroidManifest.xml如下:<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.a2" android:versionCode="1" android:versionName="1.0">    西裝外套<application android:icon="@drawable/icon" android:label="@string/app_name">        <activity android:name=".A2" android:label="@string/app_name">            <intent-filter>                <action android:name="com.action.a2" />                <category android:name="android.intent.category.DEFAULT" />            </intent-filter>        </activity>    </application></manifest>public class A3 extends 訂做禮服Activity {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        Intent mIntent = getIntent();        TextView txt = (TextView) findViewById(R.id.txt1);        txt.setText(mIntent.getStringExtra("Data"));    }}AndroidManifest.xml如下:<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.a3" 小型辦公室android:versionCode="1" android:versionName="1.0">    <application android:icon="@drawable/icon" android:label="@string/app_name">        <activity android:name=".A3" android:label="@string/app_name">            <intent-filter>                <action android:name="com.action.a3" />                <category android:name="android.intent.category.DEFAULT" />            </intent-filter>        酒店兼職</activity>    </application></manifest>  執行畫面如下:
創作者介紹

concept

iw38iwqgyr 發表在 痞客邦 PIXNET 留言(0) 人氣()