2

From an App architecture perspective in Kotlin, which is a better design approach: A) To have multiple activities in your app B) To have less activities and more fragments in your app.

Please advice. Thank You.

SVK
  • 676
  • 1
  • 5
  • 17
  • It depends on architecture you're following, *(I.e. **MVVM** is helpful when using SingleActivity and Multiple Fragments)* – Jeel Vankhede Mar 14 '19 at 13:23
  • There is no only an answer. It involved with your projects, your screens, your application flow ect. I prefer MVVM architecture If you ask about architecture. – Beyazid Mar 14 '19 at 13:24
  • It depends, on your project structure, but still, we are using different-different architecture but as per my suggestion less activities and more fragment is better :) – Nilesh Panchal Mar 14 '19 at 13:27
  • If you ask me, then Single Activity + Multiple Views (no fragments) is the most customizable solution, but you might also want to use Fragments if you don't have complex animations. Alas, you could even us Conductor controllers, or Shards. Or something totally custom. Who knows! :) Either way, this is very opinion-based unfortunately. Some people say Multi-Activity is king because it is "easy", but imo it's kinda the one that makes the least theoretical sense. My opinion, ofc. – EpicPandaForce Mar 14 '19 at 14:36
  • See https://medium.com/square-corner-blog/advocating-against-android-fragments-81fd0b462c97 for strange new ways of thinking about things. – EpicPandaForce Mar 14 '19 at 14:37

2 Answers2

3

There is no single right way to go about this decision. Depending on your application, you should first choose an architecture that suits you best. Popular choices in Android include, but are not limited to, MVP (Model View Presenter) and MVVM (Model View View Model).

Once you make that decision, you can start thinking about which method works best for you. You don't have to decide between multiple activities and activity with multiple fragments. You can have both several activities, each of which may contain multiple fragments. With the new Navigation component, part of the Architecture components, Google offers easy ways to manage fragment transactions and the back stack, which proved to be painful for most developers in the past. So, managing fragments is as easy as managing activities and you can choose what works best for you, without worrying about transactions, back stacks, navigation etc.

Myself, I prefer using different activities for separate tasks. The login flow & settings belong in separate activities, while the main actions of the applications (once the user is logged in) are handled as different fragments in a single activity that implements the navigation component. This makes navigating between fragments easier and promotes separation of concern, separating different features in different views and presenters/view models.

Overall, this topic is very subjective and there is no correct way. As other users pointed out, there are many different topics that you can look at, read different opinions and decide what works best for you.

By the way, "From an App architecture perspective in Kotlin" - the programming language you are using should not affect your architecture decision.

deluxe1
  • 737
  • 4
  • 15
1

It's an eternal question that was asked a lot of times. You'll probably won't find a definite answer. So you need to read about philosophy and decide for yourself what approach is better in your situation.

Oleg Golomoz
  • 502
  • 4
  • 12