Skip to content

Instantly share code, notes, and snippets.

@ok3141
Last active March 14, 2017 11:21
Show Gist options
  • Save ok3141/38908c20c012a81db15b to your computer and use it in GitHub Desktop.
Save ok3141/38908c20c012a81db15b 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