Skip to content

Instantly share code, notes, and snippets.

@kelvinewilliams
Created June 17, 2013 22:35
Show Gist options
  • Save kelvinewilliams/5801113 to your computer and use it in GitHub Desktop.
Save kelvinewilliams/5801113 to your computer and use it in GitHub Desktop.
How to always have a Context available... #Android
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