aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2012-06-23 11:01:37 +0200
committerSamuel Tardieu <sam@rfc1149.net>2012-06-23 14:16:00 +0200
commit9e56c969925f6aebd1c218ec21c2bd300468836e (patch)
tree27c411cc59a299974607145110be7919c0651a4c
parentc8f1047be68003f06f0e206e610914efc50f58d8 (diff)
downloadcgeo-9e56c969925f6aebd1c218ec21c2bd300468836e.zip
cgeo-9e56c969925f6aebd1c218ec21c2bd300468836e.tar.gz
cgeo-9e56c969925f6aebd1c218ec21c2bd300468836e.tar.bz2
Reclaim bitmap memory in onStop() rather than in onDestroy()
onDestroy() might be called only when the system is low in main memory, while we want to free the bitmap memory as soon as we do not need it anymore. Since the images are cached on the local filesystem, redrawing them after we come back from the image viewer does not take long.
-rw-r--r--main/src/cgeo/geocaching/cgeoimages.java28
1 files changed, 17 insertions, 11 deletions
diff --git a/main/src/cgeo/geocaching/cgeoimages.java b/main/src/cgeo/geocaching/cgeoimages.java
index aba20ae..6de6444 100644
--- a/main/src/cgeo/geocaching/cgeoimages.java
+++ b/main/src/cgeo/geocaching/cgeoimages.java
@@ -57,6 +57,9 @@ public class cgeoimages extends AbstractActivity {
// We could use a Set here, but we will insert no duplicates, so there is no need to check for uniqueness.
private final Collection<Bitmap> bitmaps = new LinkedList<Bitmap>();
+ private int message;
+ private boolean offline;
+ private ArrayList<cgImage> imageNames;
private void loadImages(final List<cgImage> images, final int progressMessage, final boolean offline) {
@@ -176,31 +179,34 @@ public class cgeoimages extends AbstractActivity {
setTitle(res.getString(img_type == SPOILER_IMAGES ? R.string.cache_spoiler_images_title : R.string.cache_log_images_title));
inflater = getLayoutInflater();
- if (imagesView == null) {
- imagesView = (LinearLayout) findViewById(R.id.spoiler_list);
- }
+ imagesView = (LinearLayout) findViewById(R.id.spoiler_list);
- final ArrayList<cgImage> images = extras.getParcelableArrayList("images");
- if (CollectionUtils.isEmpty(images)) {
+ imageNames = extras.getParcelableArrayList("images");
+ if (CollectionUtils.isEmpty(imageNames)) {
showToast(res.getString(R.string.warn_load_images));
finish();
return;
}
- final int message = img_type == SPOILER_IMAGES ? R.string.cache_spoiler_images_loading : R.string.cache_log_images_loading;
- final boolean offline = app.isOffline(geocode, null) && (img_type == SPOILER_IMAGES || Settings.isStoreLogImages());
+ message = img_type == SPOILER_IMAGES ? R.string.cache_spoiler_images_loading : R.string.cache_log_images_loading;
+ offline = app.isOffline(geocode, null) && (img_type == SPOILER_IMAGES || Settings.isStoreLogImages());
+ }
- loadImages(images, message, offline);
+ @Override
+ public void onStart() {
+ super.onStart();
+ loadImages(imageNames, message, offline);
}
@Override
- public void onDestroy() {
+ public void onStop() {
// Reclaim native memory faster than the finalizers would
- for (Bitmap b : bitmaps) {
+ imagesView.removeAllViews();
+ for (final Bitmap b : bitmaps) {
b.recycle();
}
bitmaps.clear();
- super.onDestroy();
+ super.onStop();
}
private void viewImageInStandardApp(final BitmapDrawable image) {