Why the Application and it's resources are bei

2019-07-04 06:41发布

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 screenshot from DDMS

1条回答
甜甜的少女心
2楼-- · 2019-07-04 06:52

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.

查看更多
登录 后发表回答