java - Why the getApplication() from Service Class on android can still return its sub class obj? -


as title,

i've seen code below in custom service class of kiahapplication acquire app's application obj:

((kiahapplication)super.getapplication()).setservicerunning(true);

but how android.app.service class's getapplication method know & return custom application obj?

android.app.service should not part of custom application,

and it's not recorded in application's manifest file should definition of app's members.

thank helping!

super.getapplication()
call getapplication in super class, android.app.service

((kiahapplication)super.getapplication())
cast result of super.getapplication() kiahapplication, class kiahapplication extends application

((kiahapplication)super.getapplication()).setservicerunning(true);
call setservicerunning(true); on kiahapplication class

but how service class's getapplication method know & return custom application obj?

because it's singleton. anywhere call getapplication() return same everywhere: kiahapplication instance. getapplication() can called on context. service context , can therefore call method.

note super in call not needed.


Comments

Popular posts from this blog

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

matlab - error with cyclic autocorrelation function -

php - Using grpc in Laravel, "Class 'Grpc\ChannelCredentials' not found." -