mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
Always use the application context when instantiating singletons
This commit is contained in:
parent
c3808827a8
commit
bd6cdecdb0
@ -25,8 +25,9 @@ public class Preferences {
|
||||
private static Preferences preferences;
|
||||
|
||||
public static synchronized Preferences getPreferences(Context context) {
|
||||
Context appContext = context.getApplicationContext();
|
||||
if (preferences == null) {
|
||||
preferences = new Preferences(context);
|
||||
preferences = new Preferences(appContext);
|
||||
}
|
||||
return preferences;
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ public abstract class Contacts {
|
||||
* @return Appropriate {@link Contacts} instance for this device.
|
||||
*/
|
||||
public static Contacts getInstance(Context context) {
|
||||
Context appContext = context.getApplicationContext();
|
||||
if (sInstance == null) {
|
||||
/*
|
||||
* Check the version of the SDK we are running on. Choose an
|
||||
@ -41,9 +42,9 @@ public abstract class Contacts {
|
||||
* The new API was introduced with SDK 5. But Android versions < 2.2
|
||||
* need some additional code to be able to search for phonetic names.
|
||||
*/
|
||||
sInstance = new ContactsSdk5p(context);
|
||||
sInstance = new ContactsSdk5p(appContext);
|
||||
} else {
|
||||
sInstance = new ContactsSdk5(context);
|
||||
sInstance = new ContactsSdk5(appContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,11 +18,12 @@ public class TracingPowerManager {
|
||||
private Timer timer = null;
|
||||
|
||||
public static synchronized TracingPowerManager getPowerManager(Context context) {
|
||||
Context appContext = context.getApplicationContext();
|
||||
if (tracingPowerManager == null) {
|
||||
if (K9.DEBUG) {
|
||||
Log.v(K9.LOG_TAG, "Creating TracingPowerManager");
|
||||
}
|
||||
tracingPowerManager = new TracingPowerManager(context);
|
||||
tracingPowerManager = new TracingPowerManager(appContext);
|
||||
}
|
||||
return tracingPowerManager;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user