android memory management in activity lifecycle

前端 未结 5 1548
小鲜肉
小鲜肉 2020-12-25 13:47

My question is a little bit complicated.

I want to understand how the app treats resources (especially images for backgrounds, buttons, etc.) when Activity is starte

5条回答
  •  天涯浪人
    2020-12-25 14:34

    You should design your app so that it's memory usage is low, but you can count on the framework do it's best in memory management. So, do not work too hard with removing unused stuff, only in cases when it's obvious that your app is eating too much memory.

    When the available memory goes down, the framework will stop and remove activities and services which are not associated with the current task. If your app eats up even more memory, the framework will stop your activities which are in the background. Then comes the services associated with your app and the last one to finish off will be the current activity.

    When the framework stops an activity it does keep record of the activity stack, the intents used for starting the activity and the bundle returned by onSaveInstanceState(), so it can recreate the last known state of the activities. Also, the framework can unload unused resources (drawables, etc.) when not in use and reload them when needed.

提交回复
热议问题