Reputation: 1893
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.)
Upvotes: 17
Views: 13146
Reputation: 6244
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
}
Upvotes: 47