我能够从图库中下拉图像并将其添加到图像视图,但是当我退出应用程序并再次打开它时,图像消失了。我该如何保存该图像以便使其停留在那里。打开图库方法:
private void openimage() {
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, IMAGE_CODE);
}
在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。但这应该有效