I want to get ConnectivityManager from Application Context.
But I'm not sure It will be same when get from Activity Context.
Where can I find a clue?
I can't find implementation of Application#getSystemService()..
CodePudding user response:
That should be fine. The main things that are different in the Activity context are resources, which can be effected by the theme of the activity, the orientation, etc. System services should be the same across the app, they represent some external service wrapper managed by the OS.
CodePudding user response:
getSystemService
is defined in Context
class and every class which is child of Context
can access this method directly . That includes Application
, Activity
, Service
.
getApplication().getSystemService(Context.CONNECTIVITY_SERVICE);
getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
Both are valid . also u might want to check getApplication() vs. getApplicationContext()