(upbeat music and keys tapping)
Before I move on, many new programmers struggle
with this idea that something can be of more than one type.
So looking at it AddEditFragment on line 30
you can see that we've declared listener
to be an unsafe clicked object
and that means that it's guaranteed
to implement the interface and can be used
whenever an object of type unsafe clicked is needed.
But any class can implement the interface.
Objects of that class can then be of type unsafe clicked,
but they still have the base type of their class.
So we get past the activity in onAttach,
down here on line 60.
But it's pathed so you can see
it is an object of type context.
Because our activity implements
the OnClickListener interface we can
assign the reference to it, to Listener .
That doesn't alter what the object was
it just means that we can use it
in place of OnClickListener.
It's also still a context and it's also
an AppCompatActivity and the reason for that
is that's because what we've declared
our activity to be, back here,
in our declaration of main activity,
you'll see that on line 17.
It's also still a context
and it's also an AppCompatActivity.
Alright, so you might be wondering
how it can also be a context.
So if we control click
or command click on AppCompatActivity,
depending on your version of Android Studio,
and whether Google have fixed the source code
you may get this or you might get
directly to the source code,
in any event you can click on accept if you get this,
and we'll still get to see the code anyway,
at the moment because of the way Android SDK
has been updated Google haven't got
the sources working for version 28 of the Android SDK,
and that's the reason why
the decompiler's kicked in automatically.
Alright so moving on though,
we come down here to the declaration
for AppCompatActivity, you can see here,
that it extends fragment activity
so that means our main activity
can also be used where fragment activity's needed.
So let's now see what fragment activity is,
by control or command clicking it.
So on the current API 20 at source,
you can see that that's extending support activity.
If you're targeting API 27 by the way
it extends base fragment activity API 16
but the principle is still the same.
You'll find a lot of inheritance like this
by the way when using the support libraries.
Right so let's keep going here, let's click on,
control or command click support activity,
and you can see that support activity
extends activity and moving down
click on activity, activity extends ContextThemeWrapper,
keep going, I did say there was a lot of this,
this is one mechanism that Google used
for providing backwards compatibility by the way.
So clicking on,
control or command clicking ContextThemeWrapper,
you can see now that ContextThemeWrapper
extends ContextWrapper
and click onto ContextWrapper,
control or command click,
you can see that ContextWrapper extends Context.
So that means that an instance of AppCompatActivity
can be used where any of those classes are needed,
because of inheritance it contains all
of the methods and properties of all its base classes
and therefore can be classed to any one of them.
Right, so let's close this down.
And noting that in some cases we did get
some of the proper source code working,
but not all of it, so clearly there's a bug there.
Which is the reason why we've got some working
but the other one's we only got the decompiled version.
I'm sure Google will fix that in time.
Anyway, we'll close all those down.
Alright, so I just closed down everything now.
We can open up what we need in the next video.
And speaking of that next video,
we'll see how to remove the up button from the toolbar.