Activity Layout Fragment attribute class: vs android:name

In case you wonder whether to use:

<fragment class="myapp.MyFragment" ..


<fragment android:name="myapp.MyFragment" ..

Well it doesn’t really matter. You can use both.

Lets see why in Activity.onCreateView source:

String fname = attrs.getAttributeValue(null, "class");
TypedArray a = context.obtainStyledAttributes(attrs,;
if (fname == null) {
    fname = a.getString(;

So it seems it first checks for ‘class’ and if not there then for ‘android:name’.