Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@daolq
Forked from ok3141/AppHolder.java
Created July 20, 2016 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daolq/d62a64cde4fc59e4ea39eb206363d9e5 to your computer and use it in GitHub Desktop.
Save daolq/d62a64cde4fc59e4ea39eb206363d9e5 to your computer and use it in GitHub Desktop.
Short snippet for reaching instance of Application entity in Android
public class AppHolder {
private static final android.app.Application APP;
public static android.app.Application getApp() {
return APP;
}
static {
try {
Class<?> c = Class.forName("android.app.ActivityThread");
APP = (android.app.Application) c.getDeclaredMethod("currentApplication").invoke(null);
} catch (Throwable ex) {
throw new AssertionError(ex);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment