-1

I am currently writing an Android app for my Masters final project. The app has two Activities and both have layouts corresponding to each activity. I also have a settings activity with settings fragment but I am not concerned about this one.

Activity A currently has a Spinner and a button which when pressed will do some stuff and then launch a Activity B. Activity B displays a chart, contains a couple of actions and a button to go back to Activity A.

Neither of these activities have Fragments currently but I am curious if it would be better to include Fragments. As far as I can tell using a Fragment wouldn't hinder performance so at this point it would be a cosmetic change.

cmackie21
  • 53
  • 8
  • My question is why? I prefer to add code if it is required. If you have future scope to have multiple fragment or it is possible that by using fragment you are going to reuse it somewhere else then please go ahead. Please find the answer of why :) – Ramit Aug 16 '16 at 13:18
  • if you consider a single-page layout for larger screens, yes, absolutely. – njzk2 Aug 16 '16 at 13:28

2 Answers2

1

Fragments are usually needed if you need to re-use some specific layout.

E.g--> If you have an app which displays movies, you can click and get movie details.

Here it would be better to use fragments as the layout would be the same for each movie and only the content would change inside.

In your case however, since there is not need for such frequent scenarios, you really do not need fragments.

Kushan
  • 5,855
  • 3
  • 31
  • 45
  • This is what I thought, because for each set of options that can be set in the Settings/Activity A's Spinner there has be to be a different chart, which is drawn upon the launching of Activity B. If my application was of bigger scope maybe it would be necessary but I think as it is I shall leave it as is. Thanks! – cmackie21 Aug 16 '16 at 13:26
  • glad it helped you... here check this post out, it will help you in future http://stackoverflow.com/questions/20306091/dilemma-when-to-use-fragments-vs-activities – Kushan Aug 16 '16 at 13:28
1

If you want to change the content without changing your activity due to some actions of user, implementing UIs inside Fragments can be useful. Just set the the desired fragment inside Activity by using its FragmentManager. However, otherwise don't think about such change (shifting lots of code/layout from activities to fragments) in the code.

Ugurcan Yildirim
  • 5,973
  • 3
  • 42
  • 73