Android學習筆記(十一) Intent

來源:互聯網
上載者:User

標籤:getx   strong   預設   方法   cti   學習筆記   putextra   start   color   

一、Intent對象的基本概念

  -Intent是Android應用程式組件之一
  -Intent對象在Android系統當中表示一種意圖
  -Intent當中最重要的內容是action與data

二、Intent對象的基本使用方法

  Intent intent = new Intent();
  intent.setClass(MainActivity.this,OtherActivity.class);
  //此處放入putExtra語句用於存放資料
  startActivity(intent);

三、使用Intent在Activity之間傳遞資料

  -使用putExtra()系列方法向Intent對象當中儲存資料
    intent.putExtra("com.package.Age",20);
      //存放的值是一個索引值對。第一個參數是名稱,需要包含包名;第二個是值
  -使用getXXXExtra()系列方法從Intent對象當中取出資料(在另一個Activity中)
    Intent intent = getIntent()
    int age = intent.getIntExtra("com.package.Age",10);
      //XXX是資料類型;第一個參數是名稱,需要包含包名;第二個參數是預設值,即取出資料失敗所返回的值

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.