Intent 可以用來執行許多動作,這裡我們使用Intent來啟動另一個Activity Bundle 可以放入不同類型的物件,以便在新Activity中取用
1 2 3 4 5 6 7 | Intent intent = new Intent(MainActivity. this ,ResultActivity. class ); //建立新Intent來開啟ResultActivity Bundle bundle = new Bundle(); //建立新Bundle物件 bundle.putBooleanArray( "spaced" , spaced); //放入物件 bundle.putInt("標籤名", 目標物件); bundle.putInt( "columns" , columns); bundle.putInt( "inputQuantity" , inputQuantity); intent.putExtras(bundle); //在Intent中加入Bundle物件 startActivity(intent); //執行Intent |
當你在目標Activity中,欲取出物件時
1 2 3 4 | Bundle bundle = this .getIntent().getExtras(); //取得此次呼叫Intent所附帶的Bundle spaced = bundle.getBooleanArray( "spaced" ); //用標籤名取得對應元件 columns = bundle.getInt( "columns" ); inputQuantity = bundle.getInt( "inputQuantity" ); |
沒有留言 :
張貼留言