In iOS I may write an entire application using a single UIViewController and simply adding the entire application within a UIView hierarchy. This works ok as the UIViewController gets a notification when the memory situation is bad and lets the developer do some manual memory management/optimization.
Is there an equivalent to this in Android?
Could I write an entire application in a single activity and stack fragments on top of this?
What implications would this have on memory usage as as far as I understand, this of circumvents the activity lifecycle management and the entire stack of fragments would remain in memory - or am I wrong?
You can use multiple instances of the same fragment class within the same activity, in multiple activities, or even as a child of another fragment.
Briefly, the Single-Activity Architecture is the architecture that has only one Activity or a relatively small number of Activities. Instead of having one Activity represent one screen, we view an Activity as a big container with the fragments inside the Activity representing the screen.
No. it is called only once when it is attached with activity. It is used to initialize the fragment.
Is there an equivalent to this in Android?
Not from a memory-management standpoint. You are not explicitly told of low heap space. Use of things like SoftReference
can help, but that's more at the virtual machine level.
Could I write an entire application in a single activity and stack fragments on top of this?
If you wanted to, yes.
What implications would this have on memory usage as as far as I understand, this of circumvents the activity lifecycle management and the entire stack of fragments would remain in memory - or am I wrong?
The "entire stack of fragments" would be in memory regardless of whether they are hosted by 1 activity or N activities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With