Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm sorry that the answer of this question wasn't actually possible to have with the elements I gave in my question.</p> <p>Indeed, as mentioned in another question here: <a href="https://stackoverflow.com/questions/9626270/why-are-all-my-bitmaps-upsampled-200">Why are all my bitmaps upsampled 200%?</a>, I put my pictures in the <code>drawable</code> folder, which, on a xhdpi screen like mine, will cause Android to upsample everything twice (to match xhdpi against mdpi), and will result in a 400% memory usage (twice the width and twice the height so 4 times as many pixels).</p> <p>One more thing, since I don't want the user to be able to go back (see the <code>finish()</code> right after the <code>startActivity()</code>), here's what I put in the <code>onPause()</code>:</p> <pre><code>private void unbindDrawables(View view) { if (view.getBackground() != null) { view.getBackground().setCallback(null); } if (view instanceof ViewGroup) { for (int i = 0; i &lt; ((ViewGroup) view).getChildCount(); i++) { unbindDrawables(((ViewGroup) view).getChildAt(i)); } ((ViewGroup) view).removeAllViews(); } } </code></pre> <p>This is some code I got here on StackOverflow (for example here: <a href="https://stackoverflow.com/questions/7044770/drawable-vs-single-reusable-bitmap-better-with-memory">Drawable vs Single reusable Bitmap better with memory?</a>).</p> <p>Here are my remarks about this code and why every line is important:</p> <ul> <li>The <code>setCallback(null)</code> removes the reference to the activity, so that it can be garbage collected. If you don't do this, all the views will stay in memory.</li> <li>You also need to call it from <code>onPause</code>, because <code>onDestroy</code> is not guaranteed to be called.</li> <li>You may need to cause a garbage collection after this, in order to help the GC understand that some references to objects that were made orphans and that can be GC'd. Just call <code>System.gc()</code>.</li> </ul> <p>This is the resulting <code>onPause</code> code, with the main layout of your activity having the id <code>top_layout</code>:</p> <pre><code>@Override protected void onPause() { super.onPause(); unbindDrawables(findViewById(R.id.top_layout)); System.gc(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload