M.Yogeshwaran
M.Yogeshwaran

Reputation: 1469

Why we Choosing Fragment over Activity?

My doubt is why we choosing fragment over activity even i too read that it is reusable i has its own life cycle etc etc. But as a beginner its quite difficult to work on it . Then i Have an another doubt to so far what i did in my project is i have only two activity one is for login and another one is for navigation drawer and action bar rest of things are all fragment which comes under activity 2 is it right way to do with or am making mistake . Many fragments are coming under activity 2 like multiple fragment inside a fragment is it right way it may be dumb question as a beginner is quiet difficult to understand for me can anyone clarify my doubt

Upvotes: 2

Views: 619

Answers (2)

Access Denied
Access Denied

Reputation: 9461

Fragments were invented for tablets in order to combine several fragments on one screen. Most commonly they are used in master detail relationships. Look at this question from this point of view. Does it make sense to put two fragments on one screen? Are they connected?

Read this article one more time to clarify when fragments are needed. http://developer.android.com/guide/components/fragments.html

Upvotes: 2

brwngrldev
brwngrldev

Reputation: 3704

1) You don't have to use fragments if you don't feel they are necessary for your application.

2) Having multiple activities is fine. Most applications do.

3) Having fragments inside fragments is permissible, but you should just be aware that it can cause odd behavior in your application if you are not familiar with the lifecycle events.

4) In the Android Dev Summit (2015), a great overview of a sample Android architecture was presented, I encourage you to view it: here

Hope this helps to clarify things some.

Upvotes: 0

Related Questions