从应用关闭后,从图库中选择的图像从Imageview中消失
问题描述:
我希望你能帮我解决我的简单问题。我试图从我的画廊中选择要在我的Imageview上显示的图像,但它可以正常工作,但在关闭我的应用程序后它会消失。请检查我在下面找到的代码。从应用关闭后,从图库中选择的图像从Imageview中消失
iv=(ImageView) rootView.findViewById(R.id.profpic);
iv.setOnClickListener(this);
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(
Intent.createChooser(intent, "Select a File to Upload"),
FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Toast.makeText(getActivity(), "Please install a File Manager.",
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == Activity.RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
iv.setImageURI(uri);
Log.d(TAG, "File Uri: " + uri.toString());
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
和我的XML:
<ImageView
android:id="@+id/profpic"
android:layout_width="113dp"
android:layout_height="113dp"
android:paddingRight="1dp"
android:src="@drawable/propic" />
我是新android开发任何帮助将不胜感激。提前致谢!
答
一旦你上传图片,它不会永远保留它们。您需要保留所选图像的路径Sqlite database或SharedPreference。然后在启动您的活动时,您需要使用图像路径来加载到ImageView
。
+1
感谢您的信息。我会尽力对此进行更多的研究。 – DEADPOOL 2014-08-29 03:40:55
当活动被破坏时,图像也是如此 – Eenvincible 2014-08-29 03:38:13