I apologize for not being able to provide you with some kind of official source of information, but I was also curious to find out what would happen, and decided to check it out. And, according to my tests, yes, you run the risk of running out of memory.
I had to add an incredible amount of fragments (over a hundred) to the for loop for OutOfMemoryError , but this happened. And while checking my logs, I saw that the onCreate() and onCreateView() methods were called many times, but onSaveInstance() , onPause() and onDestroy were not called at all.
For reference, this is how I added snippets to the backstack:
getSupportFragmentManager().beginTransaction().add(R.id.scene_fragment_container, mSceneFragment).addToBackStack("FOOBAR").commit();
And the added snippets were somewhat simple: ImageView , EditText , a pair of TextViews , SeekBar and ListView .
But if you do not store a huge amount of data in memory, this should not be a problem.
Later, I tried adding only 50 to the stack, killing the application and restarting it. And, as I hoped / guessed, all the fragments were restored (and the onSaveInstance() and onPause() methods were onSaveInstance() ), so my lifecycle implementation was not the problem that caused OutOfMemoryError .
Beowulf Bjornson Feb 07 2018-12-12T00: 00Z
source share