android-intent(意圖)使用-<二>

來源:互聯網
上載者:User

標籤:

1. Intent(意圖)

    intent是一組抽象地描述您想要執行“什麼”行為的資訊。它是一個對象,包含一組的資訊。

    通過它,可以啟動另一個Activity(startActivity方法);broadcastIntent傳播intent給

    BroadcastReceiver組件;啟動服務:startService(Intent);bindService(..)去與後台

    Service交流。

2.Intent的基本作用(它是一個對象,包含一組的資訊)

   1.Component name :啟動哪個Activity。

   2.Action :對於啟動Activity的後的操作。

   3.Data :你傳入什麼資料入指定的Activity

   4.Extras : 儲存索引值對,傳給指定的Activity。

   5.Category

   6.Flags

/* * 示範用一個Activity(點擊button轉到另一個介面)通過intent啟動另一個Activity * 1.在本Activity中註冊一個button * 2.為該button添加onClikListener監聽器 * 3.在該監聽器上寫入跳轉其他Activity的代碼 *   3.1 建立一個intent對象,調用setClass方法,傳入跳轉其他Activity的參數 *   3.2 調用startActivity(Intent intent)方法。 * 4.注意:另一個Activity需要建立一個xml布局檔案,並在資訊清單檔中註冊。 */public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        Button bt = (Button) findViewById(R.id.mybutton);        bt.setText("otherActivity");        bt.setOnClickListener(new OnClickListener() {                        @Override            public void onClick(View v) {                // TODO Auto-generated method stub                Intent intent=new Intent();                intent.setClass(AndroidProjectTest1Activity.this, OtherActivity.class);                AndroidProjectTest1Activity.this.startActivity(intent);            } });    }

 

android-intent(意圖)使用-<二>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.