Example usage for android.app Service getApplication

List of usage examples for android.app Service getApplication

Introduction

In this page you can find the example usage for android.app Service getApplication.

Prototype

public final Application getApplication() 

Source Link

Document

Return the application that owns this service.

Usage

From source file:com.uphyca.kitkat.storage.InjectionUtil.java

/**
 * service???/*from   w ww .ja v a2 s . c om*/
 * 
 * @param service service
 */
public static void inject(Service service) {
    inject(acquireInjector(service.getApplication()), service);
}

From source file:net.granoeste.scaffold.lifecyclecallbacks.LifecycleCallbacksSupportApplication.java

public static LifecycleCallbacksSupportApplication applicationOf(Context context) {
    if (context instanceof Activity) {
        Activity activity = (Activity) context;
        Application app = activity.getApplication();
        if (app instanceof LifecycleCallbacksSupportApplication) {
            return (LifecycleCallbacksSupportApplication) app;
        }/*from w w w.j  ava2  s  . co m*/
    }

    if (context instanceof Service) {
        Service service = (Service) context;
        Application app = service.getApplication();
        if (app instanceof LifecycleCallbacksSupportApplication) {
            return (LifecycleCallbacksSupportApplication) app;
        }
    }

    Context appContext = context.getApplicationContext();
    if (appContext instanceof LifecycleCallbacksSupportApplication) {
        return (LifecycleCallbacksSupportApplication) appContext;
    }

    if (context instanceof ContextWrapper) {
        Context base = ((ContextWrapper) context).getBaseContext();

        if (base != null) {
            if (base instanceof LifecycleCallbacksSupportApplication) {
                return (LifecycleCallbacksSupportApplication) base;
            }

            Context baseAppContext = base.getApplicationContext();
            if (baseAppContext instanceof LifecycleCallbacksSupportApplication) {
                return (LifecycleCallbacksSupportApplication) baseAppContext;
            }
        }
    }

    return null;
}

From source file:com.uphyca.lifecyclecallbacks.LifecycleCallbacksSupportApplication.java

public static LifecycleCallbacksSupportApplication applicationOf(Context context) {
    if (context instanceof Activity) {
        Activity activity = (Activity) context;
        Application app = activity.getApplication();
        if (app instanceof LifecycleCallbacksSupportApplication) {
            return (LifecycleCallbacksSupportApplication) app;
        }/*from   ww  w . j av  a2  s. c o m*/
    }

    if (context instanceof Service) {
        Service service = (Service) context;
        Application app = service.getApplication();
        if (app instanceof LifecycleCallbacksSupportApplication) {
            return (LifecycleCallbacksSupportApplication) app;
        }
    }

    Context appContext = context.getApplicationContext();
    if (appContext instanceof LifecycleCallbacksSupportApplication) {
        return (LifecycleCallbacksSupportApplication) appContext;
    }

    if (context instanceof ContextWrapper) {
        Context base = ((ContextWrapper) context).getBaseContext();

        if (base != null) {
            if (base instanceof LifecycleCallbacksSupportApplication) {
                return (LifecycleCallbacksSupportApplication) base;
            }

            Context baseAppContext = base.getApplicationContext();
            if (appContext instanceof LifecycleCallbacksSupportApplication) {
                return (LifecycleCallbacksSupportApplication) baseAppContext;
            }
        }
    }

    return null;
}