如何记住适用于imageview box的图片路径

How to remember image path which applies to imageview box

我正在开发一个简单的应用程序,其中按下按钮以从适用于图像视图框的图库中选择图像,但问题是如何记住图像路径,无论何时我退出并重新打开应用程序,相同的图像都应该出现在图像中查看框。

 <ImageView
                android:id="@+id/image1"
                android:layout_width="100dp"
                android:layout_height="200dp"
                android:src="@drawable/index"
                android:layout_margin="5dp"

                />

您可以使用共享首选项

关于图像选择

SharedPreferences sharedpreferences = getSharedPreferences("ImagePrefs", Context.MODE_PRIVATE); 
Editor editor = sharedpreferences.edit();
editor.putString("imagePath", myImagePath);
editor.commit();

然后当您启动应用程序时

SharedPreferences sharedpreferences = getSharedPreferences("ImagePrefs", Context.MODE_PRIVATE);
if(sharedpreferences.contains("imagePath")) // we have an image
{
   String path = sharedpreferences.getString("imagePath")
   //here set the image from the path
}
else
{
  //no image was ever selected
}