Created
June 27, 2016 10:47
-
-
Save ianmartorell/80b38e4e38d91812b5841a93fc75bba7 to your computer and use it in GitHub Desktop.
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 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