Android 应用程序关闭后,从库中选择的图像将从Imageview中消失
我希望你能帮我解决这个简单的问题。我正试图从我的图库中选择一个图像显示在我的Imageview上,它可以工作,但问题是,它在我关闭应用程序后消失。请检查我在下面找到的代码Android 应用程序关闭后,从库中选择的图像将从Imageview中消失,android,imageview,filechooser,Android,Imageview,Filechooser,我希望你能帮我解决这个简单的问题。我正试图从我的图库中选择一个图像显示在我的Imageview上,它可以工作,但问题是,它在我关闭应用程序后消失。请检查我在下面找到的代码 iv=(ImageView) rootView.findViewById(R.id.profpic); iv.setOnClickListener(this); private void showFileChooser() { Intent intent = new In
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开发新手,任何帮助都将不胜感激。提前谢谢 一旦你上传了图像,它就不会永远保留它们。您需要将选定图像的路径保留在或中。然后,在启动活动时,您需要使用图像路径在活动被销毁时加载到
ImageView
,图像也是如此。感谢您提供信息。我将对此进行更多的研究。