标签:
intent用于不同activity间的跳转,跳转的同时可以附带上参数(这有点像php中的$_GET[]和$_POST[])
有两个相关的函数:
intent.putExtra("key", value); //写入
value = intent.getXXXExtra("key"); //读取,XXX是相应的数据类型,如String
对于Bitmap,由于intent不支持,则需先转换成byte[]再传递。
1 private Bitmap photo_bmp = null; 2 private String nickname = null; 3 4 //Activity A: 5 private byte[] Bitmap2Bytes(Bitmap bm){ 6 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 7 bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); 8 return baos.toByteArray(); 9 } 10 11 byte buf[] = new byte[1024*1024]; 12 buf = Bitmap2Bytes(photo_bmp); 13 intent.putExtra("photo_bmp", buf); 14 intent.putExtra("nickname", nickname); 15 16 17 //Activity B: 18 byte buf[] = intent.getByteArrayExtra("photo_bmp"); 19 photo_bmp = BitmapFactory.decodeByteArray(buf, 0, buf.length); 20 nickname = intent.getStringExtra("nickname");
标签:
原文地址:http://www.cnblogs.com/fashare/p/4515671.html