-
-
Save hongyangAndroid/a6e68bf942cbc6825481 to your computer and use it in GitHub Desktop.
Short snippet for reaching instance of Application entity in Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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