Note that there are some explanatory texts on larger screens.

plurals
  1. POShould Multiple Instances of an Android Activity show up in Memory Analyzer?
    text
    copied!<p>When I click through my application navigation I find that Android is creating a new instance of the activity each time I launch the new Intent (using the following code):</p> <pre><code>Intent intent = new Intent(this, HomeActivity.class); startActivity(intent); </code></pre> <p>Based on what I've read this seems to be the default behavior. I would have guessed this means that the heap will now have multiple instances allocated to maintain the application's history. However Patrick Dubroy says in his <a href="http://www.youtube.com/watch?v=_CruQY55HOk&amp;feature=player_detailpage#t=2185s" rel="nofollow">video on Memory management</a> that only one instance of an activity should show up in your heap dump unless there's a memory leak.</p> <p>My question is two-fold: Am I correct that a new activity instance is created each time the intent is launched? If so, does having multiple instances appearing in the heap dump indicate that there is a memory leak?</p> <p><strong>Update</strong> Based on <a href="http://developer.android.com/guide/components/tasks-and-back-stack.html" rel="nofollow">the Tasks and Back Stack guide</a>: </p> <blockquote> <p>Because the activities in the back stack are never rearranged, if your application allows users to start a particular activity from more than one activity, a new instance of that activity is created and pushed onto the stack (rather than bringing any previous instance of the activity to the top). As such, one activity in your application might be instantiated multiple times (even from different tasks)</p> </blockquote>
 

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