Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android application based on single activity, multiple fragments

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?

like image 468
user204884 Avatar asked Dec 18 '11 05:12

user204884


People also ask

Can one activity have multiple fragments?

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.

What is single activity architecture Android?

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.

Can an activity containing multiple fragments can be created without having a layout attached to it?

No. it is called only once when it is attached with activity. It is used to initialize the fragment.


1 Answers

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.

like image 172
CommonsWare Avatar answered Nov 15 '22 19:11

CommonsWare