Skip to content

Instantly share code, notes, and snippets.

@ianmartorell
Created June 27, 2016 10:47
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 ianmartorell/80b38e4e38d91812b5841a93fc75bba7 to your computer and use it in GitHub Desktop.
Save ianmartorell/80b38e4e38d91812b5841a93fc75bba7 to your computer and use it in GitHub Desktop.
public class MySingleton {
private static MySingleton sInstance;
private final Context mContext;
private MySingleton(Context context) {
mContext = context.getApplicationContext();
}
public getInstance(Context context) {
synchronized (MySingleton.class) {
if (sInstance == null) {
sInstance = new MySingleton(context);
}
return sInstance
}
}
public doSomethingNeedingContext() {
mContext.getString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment