I would like to know if my given Context object is from Activity, Service or Application. Or in other words if my code is executing in background or in foreground. (By foreground i mean Activity code and threads that have been created by Activity.)
Application Context: It is the application and we are present in Application. For example - MyApplication(which extends Application class). It is an instance of MyApplication only. Activity Context: It is the activity and we are present in Activity.
In android, Context is the main important concept and the wrong usage of it leads to memory leakage. Activity refers to an individual screen and Application refers to the whole app and both extend the Context class.
To access the context object, first specify the parameter name by appending . $ to the end, as you do when selecting state input with a path. Then, to access context object data instead of the input, prepend the path with $$. .
You should be able to test if an object is a specific class using "instanceof"
if (context instanceof Activity) {
// handle activity case
} else if (context instanceof Service){
// handle service case
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With