I would like to know if my give开发者_JAVA技巧n 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.)
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
}
精彩评论