`不知道爲什麼在模擬器上運行地好好的程序,一到真機上就不行了,百度之後,各種揣測,是應爲沒有設置權限嗎?是應爲手機版本太低嗎?是因爲每次跑程序前要先卸載手機上的安裝的程序的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傳遞,就可以了。