1

I am creating activity and there are a lot of functionality. I would like to make a fragment for each feature so the desired functionality for each feature is embeded in it's own class and design is not in one big XML. Is it bad practice and does it harm functionality? Maybe it is better to create custom View class for each feature?

Heisenberg
  • 3,153
  • 3
  • 27
  • 55

3 Answers3

0

I am also new to Android, but I think it depends from whether you can/want to reuse the fragments and/or want to change parts of the activity dynamically. If not, you should use a single activity.

But I can feel your pain. My solution so far was to use the activity itself like a controller in MVC and to outsource as many methods as possible into POJOs (or maybe AsyncTasks if you use them).

I'd appreciate confirmation/dismissal from a experienced dev!

Tim Joseph
  • 847
  • 2
  • 14
  • 28
0

This might be bit late to answer but have a look at this sample MVP Sample
Fragment is very useful in decoupling the code, and implementing dedicated interfaces.

xrnd
  • 1,273
  • 3
  • 21
  • 38
0

Fragments are useful if you plan to support multiple size devices i.e. tablets & phones, TV's etc and/or orientation - they allow you to use the same "business logic" on different screen real-estates.

If you want to separate your business logic from View logic then I'd recommend using MVP

Where your Model is - storage and retrieval of data. View - Activity & Fragment (purely concerned with storing data) Presenter - a Java class that purely deals with business logic (little or no Android framework) - so it can be tested independently.

Here's another answer I wrote, which details MVP

Community
  • 1
  • 1
Zain
  • 2,336
  • 1
  • 16
  • 25