How Android interacts with our apps
It does so by calling methods that are contained within the Activity
class. Even if the method is not visible within our Java code, it is still being called by Android at the appropriate time. If this doesn't seem to make any sense, then read on.
Did you ever wonder why the onCreate
method had a strange-looking line of code just before it?
@Override
What is going on here is that we are saying to Android, when you call onCreate
, please use our overridden version because we have some things to do at that time.
Furthermore, you might remember the odd-looking first line of code in the onCreate
method:
super.onCreate(savedInstanceState)
This is telling Android to call the original/official version of onCreate
before proceeding with our overridden version. This is not just a quirk of Android – method overriding is built into Java.
There are also many other methods that we can optionally override, and they allow us to add...