退出应用程序使从图库中获取的图像消失

问题描述 投票:-3回答:1

我能够从图库中下拉图像并将其添加到图像视图,但是当我退出应用程序并再次打开它时,图像消失了。我该如何保存该图像以便使其停留在那里。打开图库方法:

  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);

        }

如您所见,我尝试使用共享首选项,但这并不麻烦。有什么建议吗?

java android navigation-drawer imageurl
1个回答
0
投票

即使您的问题不够详细,也请尝试按共享的首选项保存图像URI。但这应该有效

© www.soinside.com 2019 - 2024. All rights reserved.