title: understanding onTrimMemory( int level )
body: <p>I recently read this article on <em><a href="http://developer.android.com/training/articles/memory.html" rel="noreferrer">Managing Your App's Memory</a></em>,I strongly suggest to read it if you are an AndroidDev and never did.</p>
  
  <p>There are lots of good practices and one thing I never happen to know about is the <a href="http://developer.android.com/reference/android/content/ComponentCallbacks2.html#onTrimMemory%28int%29" rel="noreferrer">onTrimMemory(int level)</a> method called by the system on every Activity/Fragment to notify events on which memory should or could be released.</p>
  
  <p>Here is a quote from that article:</p>
  
  <blockquote>
    <p><strong>Notice that your app receives the onTrimMemory() callback with
    TRIM_MEMORY_UI_HIDDEN only when all the UI components of your app
    process become hidden from the user</strong>. This is distinct from the
    onStop() callback, which is called when an Activity instance becomes
    hidden, which occurs even when the user moves to another activity in
    your app. So although you should implement onStop() to release
    activity resources such as a network connection or to unregister
    broadcast receivers, <strong>you usually should not release your UI resources
    until you receive onTrimMemory(TRIM_MEMORY_UI_HIDDEN)</strong>. This ensures
    that if the user navigates back from another activity in your app,
    your UI resources are still available to resume the activity quickly.</p>
  </blockquote>
  
  <p>I am really interested in implementing a good memory management in my application so I am looking forward to implement the <a href="http://developer.android.com/reference/android/content/ComponentCallbacks2.html#onTrimMemory%28int%29" rel="noreferrer">onTrimMemory()</a> in the right way.</p>
  
  <p>I only have a few questions about it:</p>
  
  <ul>
  <li><p>is <a href="http://developer.android.com/reference/android/content/ComponentCallbacks2.html#onTrimMemory%28int%29" rel="noreferrer">onTrimMemory(TRIM_MEMORY_UI_HIDDEN)</a> called right after the onStop()?</p></li>
  <li><p>what "release your UI resources" means in that context? just for instance clean the Bitmap cache, or actually remove and destroy every View in the View tree? i usually destroy the Views in the <em>onDestroy()</em> or <em>onDestroyView()</em> methods, i am now wondering if i'm doing it right.</p></li>
  <li><p>is there a Twin/correspondent callback to <a href="http://developer.android.com/reference/android/content/ComponentCallbacks2.html#onTrimMemory%28int%29" rel="noreferrer">onTrimMemory(TRIM_MEMORY_UI_HIDDEN)</a>? like <em>onCreate-onDestroy</em>, <em>onStart-onStop</em>, <em>onCreateView-onDestroyView</em>. I'm asking to understand where and how i should restore the UI state after an Activity/Fragment as been brought in foreground after <a href="http://developer.android.com/reference/android/content/ComponentCallbacks2.html#onTrimMemory%28int%29" rel="noreferrer">onTrimMemory(TRIM_MEMORY_UI_HIDDEN)</a> has been called.</p></li>
  </ul>