0

This is a follow up question to this question:

Dilemma: when to use Fragments vs Activities:

When I create an Android app, I create a single (or very few) activity and leave most of the logic to fragments. The activities in my case are mainly intended to be a container for fragments which are replaced with a FragmentTransaction.

Every time I'm searching for a formal explanation with advantages of this method, I always see some metaphors or incomplete answers, like in the question I linked above.

I was recently told that when a user replace a fragment, the previous Fragment's onDestoryView is called, which helps saving space and that this is actually the main reason for using fragments over activities. Is that correct? Are there other reasons which are maybe even more significant?

Please note that I'm looking for a more technical explanation of the advantages of this method rather than knowing when I should use it. I don't want an explanation of when is it a good idea to use multiple activities or multiple fragments, but my question is more of: "considering I'm already using this method, what are my advantages?". Does it save space? Is it lighter to switch a fragment than an Activity? Something else?

Community
  • 1
  • 1
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
  • Just want to mention that you can also avoid Fragments altogether: e.g. [Conductor](https://github.com/bluelinelabs/Conductor). There are some good reasons for this: [Advocating Against Android Fragments](https://medium.com/square-corner-blog/advocating-against-android-fragments-81fd0b462c97#.xm4z7lex8) – TmTron Mar 26 '17 at 07:48
  • This is just asking for opinions. You can find as many "for" arguments as "against" arguments. It's like religion. And it doesn't belong here on Stackoverflow. – David Wasser Mar 27 '17 at 16:13
  • I'm not looking for opinions if you havn't read my question until the end. I did not ask "what is better". I asked the technical advantages of using fragment vs activities. There is nothing related to opinions about it – CodeMonkey Mar 28 '17 at 07:32
  • The answer to this question is "it depends". Therefore, in order to get a better answer you would have to post your entire application and explain to us how it is used and then we might be able to pontificate on various pros and cons of your implementation. There are many roads and they all lead to Rome. The question is pretty much irrelevant. Implement it whatever way you want to. If you find that something isn't working for you, it may be because of the chosen architecture, or it may not be. There is little point in this discussion. Sorry. Just my opinion. – David Wasser Apr 07 '17 at 17:07
  • It's basically as I already described it in the question.. The activity is there to be a container for fragments and all the screens of the applications are implemented with fragments.. If you press a button that transfer you to a different screen, this implementation calls for a FragmentTransaction which simply replaces the fragment in the activity which simulates the changing of the screen the user sees.. that's all there is to it. – CodeMonkey Apr 09 '17 at 07:20

0 Answers0