我有一个从 Parse.com 下载图像并在图像视图中显示该图像的应用程序
问题是,每当我退出应用程序(使用后退按钮)并返回图像时,图像就消失了。
我怎样才能使图像保持不变?
(例如:当您在 Twitter 上更新您的个人资料照片并离开应用程序并返回您的个人资料照片时仍会显示)
任何帮助将不胜感激,这非常重要。
主要活动:
public class MainActivity extends Activity {
Button button;
private ProgressDialog progressDialog;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from main.xml
setContentView(R.layout.activity_main);
// Show progress dialog
// Locate the button in main.xml
button = (Button) findViewById(R.id.button);
// Capture button clicks
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
progressDialog = ProgressDialog.show(MainActivity.this, "",
"Downloading Image...", true);
// Locate the class table named "ImageUpload" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"ImageUploads");
// Locate the objectId from the class
query.getInBackground("h3FvFzrHPr",
new GetCallback<ParseObject>() {
public void done(ParseObject object,
ParseException e) {
// TODO Auto-generated method stub
// Locate the column named "ImageName" and set
// the string
ParseFile fileObject = (ParseFile) object
.get("imageContent");
fileObject
.getDataInBackground(new GetDataCallback() {
public void done(byte[] data,
ParseException e) {
if (e == null) {
Log.d("test",
"We've got data in data.");
// Decode the Byte[] into
// Bitmap
Bitmap bmp = BitmapFactory
.decodeByteArray(
data, 0,
data.length);
// Get the ImageView from
// main.xml
ImageView image = (ImageView) findViewById(R.id.image);
// Set the Bitmap into the
// ImageView
image.setImageBitmap(bmp);
// Close progress dialog
progressDialog.dismiss();
} else {
Log.d("test",
"There was a problem downloading the data.");
}
}
});
}
});
}
});
}
}