use getApplicationContext() when storing a passed in Context

getApplicationContext() returns the Context of the application, which is
guaranteed to have the same life as the app itself.  Other Contexts, like
an Activity, might go away during runtime.
This commit is contained in:
Hans-Christoph Steiner 2014-05-25 22:46:28 -04:00
parent 09fb7969b4
commit 09db3524cf
2 changed files with 2 additions and 2 deletions

View File

@ -73,7 +73,7 @@ public class LocalRepoManager {
}
private LocalRepoManager(Context c) {
context = c;
context = c.getApplicationContext();
pm = c.getPackageManager();
assetManager = c.getAssets();
prefs = PreferenceManager.getDefaultSharedPreferences(c);

View File

@ -27,7 +27,7 @@ public class LocalHTTPD extends NanoHTTPD {
super(FDroidApp.ipAddressString, FDroidApp.port);
this.logRequests = false;
this.webRoot = webRoot;
this.context = context;
this.context = context.getApplicationContext();
if (useHttps)
enableHTTPS();
}