Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Tom Finet
Tom Finet
7,027 Points

Should I use a fragment or an activity?

I am building my first android app and cannot make up my mind as to what to use a fragment or an activity.

In my app I have a MainActivity which holds a FriendFragment and other fragments which can be navigated to using the navigation drawer. In this FriendFragment, the action bar provides an action to find friends.

This is where I have a problem, should I create and add a fragment from the FriendFragment or should I start a new FindFriendActivity to handle this. All this activity/fragment should do is provide back navigation to the previous fragment and the ability to suggest friends.

An advantage of using a fragment is that it may be more suitable for a tablet layout compared to an activity.

Which should I use, a fragment or an activity?