Created
June 17, 2013 22:35
-
-
Save kelvinewilliams/5801113 to your computer and use it in GitHub Desktop.
How to always have a Context available... #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 MyApplication { | |
public static Context ApplicationContext = null; | |
public static Context getContext() { | |
return ApplicationContext; | |
} | |
} | |
// In your startup activity set the context. | |
MyApplication.ApplicationContext = getApplicationContext(); | |
// Wherever you need the context | |
Context c = MyApplication.getContext(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment