Skip to content

Instantly share code, notes, and snippets.

@hongyangAndroid
Forked from ok3141/AppHolder.java
Created February 28, 2016 10:59
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 hongyangAndroid/a6e68bf942cbc6825481 to your computer and use it in GitHub Desktop.
Save hongyangAndroid/a6e68bf942cbc6825481 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