I have an idea they both get the 'context' so that functions know how they fit into the scheme of things, is this right?
Any clues for the evolving ape?
I have an idea they both get the 'context' so that functions know how they fit into the scheme of things, is this right?
Any clues for the evolving ape?
this
is a reference to the current class you are. It can be an Activity
, Fragment
, Adapter
, View
, etc. And when you use it what you are doing is just passing a reference of the current object of that class.
Let's say you are working on a custom View
. Anywhere in the code of that view where you call this
will be interpreted as the View itself, so the value of this
changes depending on what class you are.
The method getActivity()
is defined only in the Fragment
class and any other class extending Fragment
and this method returns and Object of the type Activity
.
On Android development is very common mixing those two because most of the applications code is in Activity
classes, and calling this
on an Activity
class will return an Activity
object but as you can see they are not the same thing.
You can read more here