0

The demo project provided by google for using the Youtube API. which allow developers to include a youtube player inside there app. I noticed to demoes one is using YouTubePlayerView and the other used YouTubePlayerFragment. I can't really figure out the difference.

Maybe there is a technical difference. What is it?

hasan
  • 23,815
  • 10
  • 63
  • 101

1 Answers1

1

Fragments: "A Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities. You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running (sort of like a "sub activity" that you can reuse in different activities)."

http://developer.android.com/guide/components/fragments.html

Views: "This class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). The ViewGroup subclass is the base class for layouts, which are invisible containers that hold other Views (or other ViewGroups) and define their layout properties."

http://developer.android.com/reference/android/view/View.html

What's the difference? "So, the main reason to use Fragments are for the backstack and lifecycle features. Otherwise, custom views are more light weight, simpler to implement, and have the advantage that they can be nested."

What is the benefit of using Fragments in Android, rather than Views?

Hopefully this help clears things up.

Community
  • 1
  • 1
Dave S
  • 3,378
  • 1
  • 20
  • 34
  • how can I extend YouTubeBaseActivity as long as my base activity? – hasan May 20 '14 at 22:07
  • 1
    I don't understand what you are asking but I probably can't help you there anyway as I haven't used the youtube api. – Dave S May 20 '14 at 22:16