`不知道为什么在模拟器上运行地好好的程序,一到真机上就不行了,百度之后,各种揣测,是应为没有设置权限吗?是应为手机版本太低吗?是因为每次跑程序前要先卸载手机上的安装的程序的App吗?
结合代码综合分析之后,我顿悟了,在界面跳转的时候,我用intent传递图片而且传了好几张,于是乎,真机运行时,抛出了这个异常:!!! FAILED BINDER TRANSACTION !!!
解决办法网上有很多的,我也试了很多,有的根本就解决不了问题,最后怎么办呢?
既然传递图片太大了,不行,那么换个思路,传递图片路径不就行了吗?说到这,大家都明白了吧!
1.保存图片,记下路径picturePath
2.用intent传递String picturePath
3.接收picturePath后Bitmap b=BitmapFactory.decodeFile(picturePath);
这样你的图片就传过来了。
至于怎样保存图片,传递路径,贴代码吧:“
public String saveBitmap(){
//获得系统当前时间,并以该时间作为文件名
SimpleDateFormat formatter = new SimpleDateFormat ("yyyyMMddHHmmss");
Date curDate = new Date(System.currentTimeMillis());//获取当前时间
String str = formatter.format(curDate);
String paintPath = "";
str = str + "paint.png";
File dir = new File("/sdcard/notes/");
File file = new File("/sdcard/notes/",str);
if (!dir.exists()) {
dir.mkdir();
}
else{
if(file.exists()){
file.delete();
}
}
try {
FileOutputStream out = new FileOutputStream(file);
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
//保存绘图文件路径
paintPath = "/sdcard/notes/" + str;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return paintPath;
}
saveBitmap返回的是图片路径,如果保存的是多张图片就用数组存起来,再用intent传递,就可以了。