我正在编写一个将字符串存储在 SQLite 数据库中的应用程序,它表示 /sdcard/ 上图像的文件路径。我在我的一项活动中有此代码onCreate()
:
final Intent receivedIntent = getIntent();
String imageStr = receivedIntent.getExtras().getString("picture");
ImageView imageView = (ImageView) findViewById(R.id.pPicture);
File file = new File (imageStr);
if (file.exists()) {
Bitmap bitmap = BitmapFactory.decodeFile(imageStr);
imageView.setImageBitmap(bitmap);
}
该代码在我第一次加载活动时有效,但是当我在屏幕方向之间切换时,它会使我的应用程序崩溃。关于我能做些什么来解决这个问题的任何想法?我希望蜜蜂能够继续在方向之间切换,但我不需要每次都刷新。
另外,我有点新,所以如果可能的话,请尽量让你的答案不要太复杂。
请注意,该文件在所有情况下都存在。