【android基础】之intent传递数组[应用于activity之间传递图片参数等]

activity中加入
 
Bundle b=new Bundle(); b.putIntArray(key, new int[]{value1, value2}); Intent i=new Intent(context, Class); i.putExtras(b); 


需要得到数据的activity中加入

Bundle b=this.getIntent().getExtras(); String[] array=b.getIntArray(key);
 
实例
第一步:
public void myClick(View target) {
  Intent intent;
  switch (target.getId()) {
  case R.id.mg1:
   Bundle bundle = new Bundle();
   bundle.putIntArray("mThumbIds", new int[]{R.drawable.mm1, R.drawable.mm2,R.drawable.mm3, R.drawable.mm4});
   bundle.putIntArray("mImageIds", new int[]{R.drawable.mm1_thumb, R.drawable.mm2_thumb,R.drawable.mm3_thumb, R.drawable.mm4_thumb});
   intent  = new Intent(ImageListActivity.this, ImageSwitcherActivity.class);
   intent.putExtras(bundle);
   startActivity(intent);
   break;
  case R.id.mg2:
.........
 
 
第二步:
 
this.mImageIds = this.getIntent().getExtras().getIntArray("mImageIds");
this.mThumbIds = this.getIntent().getExtras().getIntArray("mThumbIds");
 
 
注意取值的时候要写在onCreate方法里面(原因嘛,不解释。自己思考)
 
 
 
 
 
 
 
 
 

你可能感兴趣的:(android,String,Class)