user412759
user412759

Reputation: 2415

When does the activity object really get killed after calling finish()?

I created a thread in my activity, and that thread will print out the value of my instance variables in my activity after running for about 10 seconds. I pressed the back key to destroy my activity before the thread prints out the values, and when the thread reaches that line of code, it can still print out the values correctly. That means even though the activity is finished, the java object of the activity is still there. Will the object always be there? Or it is just waiting to be GCed? Or it will be killed only when Android needs memory?

Upvotes: 0

Views: 832

Answers (1)

Vincent Mimoun-Prat
Vincent Mimoun-Prat

Reputation: 28541

See this question: your Thread will not be garbage collected even if the activity is destroyed. You need to specifically request your Thread to terminate in your onFinish() function. Then either let it kill itself or do a join() in order to wait for it to actually terminate.

Upvotes: 2

Related Questions