问题
I have a simple Hello World application
public class TestLeaksOnFinish extends Activity
{
static int ctr = 0;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView t = new TextView(this);
t.setText("Hello World! "+ctr++);
setContentView(t);
}
}
When I run this multiple times, each time followed by pressing BACK, I see that ctr increases each time, indicating that the Activity is not killed completely after BACK.
This is also confirmed by dumping the HPROF file in DDMS after pressing BACK.
This file still contains my TestLeaksOnFinish activity class.
Can someone explain why this Activity is still present in the heap dump after pressing BACK?
When I list the incoming references, I get the following
回答1:
In Android activities dont get killed they'll just be moved to background.That's how Android works you cant kill an Application or basically there's not quit as you know.It'll just stay in the background and in the memory.
When you run out of memory then the system starts to kill the Application processes according to priority that the system gives to every application itself.
来源:https://stackoverflow.com/questions/8149017/why-the-application-and-its-resources-are-being-kept-in-the-memory-after-exitin