Android and finish on onDestory release resources

onDestoryActivity is a final step in the life cycle, almost all of the resources released over, will be performed.
And finish, after the implementation of Activity will be of immediate effect.

Activity may not go onDestory, but will gofinish .

If we put all the resources on the operation of the release onDestory, it may lead into the next Acitvity of time, on an Activity in code still running.
for instance:

  • We opened a page in the A registers a broadcast, when listening to something went performs A of a () method, and was broadcast in the anti-registration method onDestory
  • A page opens after page of B, A page may not be timely to go onDestory, lead A moment received a broadcast, and then perform a (), which will lead to B page some unexpected things.

to sum up

  • Some require timely removal resources on finish()ways to release. Such as anti-registered broadcast, EventBus (as the case may see event did), timer
  • Some do not immediately released on onDestory()doing. For example ButterKnife, property set some object animation.
Published 248 original articles · won praise 99 · Views 100,000 +

Guess you like

Origin blog.csdn.net/rikkatheworld/article/details/102836743