2018年10月30日 星期二

[Android]_ch6.2_傳遞資料給其他活動




在Intent物件攜帶傳遞資料是使用Bundle物件,它是一種目錄物件(Dictionary Object,儲存鍵與值的對應資料),可以儲存字串型態鍵值對應的各種資料型態資料,如下所示:
//1.建立Intent物件
Intent myIntent = new Intent();
//2.藉由setClass()方法設定來源與目的地類別
myIntent.setClass(First.this, Second.class);
//3.建立Bundle物件,利用putString(鍵值,資料)方法新增字串資料
       Bundle bundle = new Bundle();
       bundle.putString("HEIGHT", height.getText().toString());
       bundle.putString("WEIGHT“, weight.getText().toString());
//4.使用Intenet物件的puExtras()方法,附加Bundle物件
       myIntent.putExtras(bundle);
//5.啟動活動
       startActivity(myIntent);

沒有留言:

張貼留言

Ether.fi Cash Card 一張所有人必備的加密貨幣信用卡   [Ether.fi Cash Card] : https://www.ether.fi/app/cash/sign-up?ref_code=d27f8523 ------國際交易所------ [Bitg...