android Activities classes and objects

49 Views Asked by At

I am new to android development. So I have a question about activities. On Google developer, they say you have to make a class which is inheriting from the class Activity. So far so good. Now I am thinking an Activity is a class, which leads to my major problem. So when activity is a class how can it invoke all the live cycle methods. In Java, I learnt there must be an object of a class to invoke methods and actions. So when activity is not an object but a class, how is this possible.

Kindest regards Jan

2

There are 2 best solutions below

0
Finkes On

When a user starts your app the android operating system will instantiate an object based on your class which must be a subclass of Activity.

The operating system will use that object and call the lifecycle hooks (e.g. onCreate, onResume, ...) which you implented in your activity subclass when one of the related lifecycle events happens.

0
Alok Gupta On

Here it is clearly mentioned under CREATING AN ACTIVITY header, that system calls the callback methods, based on which event has occurred. Suppose user is interacting with your activity, then using the object created by the OS for that activity, all the callback methods will be executed. Please refer.