问题描述:由于某些原因(如旋转屏幕,或内存不足时)造成Activity被destroy ,当再次回到该Activity时,系统会recreate 该Activity , if your activity instance is destroyed and recreated, the state of the layout is restored to its previous state with no code required by you. 如果在该Activity的onCreate中存在add Fragment的代码(未区分是create 还是recreate activity),则会再次add一次该Fragment,造成该Activity中会内嵌多个相同的Fragment. 所以最终原因还是由于Activity的生命周期造成的。
Recreating an Activity
There are a few scenarios in which your activity is destroyed due to normal app behavior, such as when the user presses the Back button or your activity signals its own destruction by calling finish()
. The system may also destroy your activity if it's currently stopped and hasn't been used in a long time or the system needs to free up resources and must shut down cached processes to recover memory.