退出应用程序会导致从库中拍摄的图像消失



我可以从我的图库中提取图像并将其添加到图像视图中,但当我退出应用程序并再次打开它时,图像就不见了。如何保存此图像,使其保持不变。开放式画廊方法:

private void openimage() {
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, IMAGE_CODE);
}

In-onActionResult:

if (requestCode == IMAGE_CODE) {
Uri contentURI = data.getData();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("image", String.valueOf(contentURI));
editor.commit();
Glide.with(this).load(contentURI).into(imageView);
}

正如你所看到的,我尝试过使用共享偏好,但没有成功。有什么建议吗?

尝试将图像URI保存在共享偏好上

最新更新