Return the right thing from Context.getApplicationContext()

Previously, this would always return the app context for the first application
ever instantiated in the process.  Usually this is fine, since usually there
will be one process per application, but in the case of shared-process apps,
it causes activities/views to try to access the wrong set of resources, be
unable to access their proper derived-class Application objects, etc.

Fixes bug #2513901

Change-Id: Ie19f2a86583c5d927db4d84a4262077450e37539
This commit is contained in:
Christopher Tate
2010-03-23 17:14:36 -07:00
parent 23aea6df06
commit eb9e9ec061
2 changed files with 7 additions and 2 deletions

View File

@@ -278,6 +278,10 @@ public final class ActivityThread {
int mClientCount = 0;
Application getApplication() {
return mApplication;
}
public PackageInfo(ActivityThread activityThread, ApplicationInfo aInfo,
ActivityThread mainThread, ClassLoader baseLoader,
boolean securityViolation, boolean includeCode) {
@@ -648,7 +652,7 @@ public final class ActivityThread {
}
mActivityThread.mAllApplications.add(app);
mApplication = app;
if (instrumentation != null) {
try {
instrumentation.callApplicationOnCreate(app);

View File

@@ -260,7 +260,8 @@ class ContextImpl extends Context {
@Override
public Context getApplicationContext() {
return mMainThread.getApplication();
return (mPackageInfo != null) ?
mPackageInfo.getApplication() : mMainThread.getApplication();
}
@Override