Bug 751690: isApplicationInBackground() should return correct values r=mfinkle

This commit is contained in:
Sriram Ramasubramanian 2012-05-08 16:40:12 -07:00
parent 417b4ef069
commit bcd38671f4
2 changed files with 21 additions and 8 deletions

View File

@ -13,7 +13,7 @@ import android.content.ComponentName;
public class GeckoActivity extends Activity {
private boolean hasStarted = false;
private boolean isGeckoActivityOpened = false;
private boolean mGeckoActivityOpened = false;
@Override
public void onPause() {
@ -31,7 +31,7 @@ public class GeckoActivity extends Activity {
// Avoid resume notifications in startup path.
if (hasStarted && (getApplication() instanceof GeckoApplication)) {
((GeckoApplication) getApplication()).onActivityResume(this);
isGeckoActivityOpened = false;
mGeckoActivityOpened = false;
} else {
hasStarted = true;
}
@ -54,15 +54,19 @@ public class GeckoActivity extends Activity {
// If we call an activity from another package, or an open intent (leaving android to resolve)
// component has a different package name or it is null.
ComponentName component = intent.getComponent();
isGeckoActivityOpened = false;
mGeckoActivityOpened = false;
if (component != null &&
component.getPackageName() != null &&
component.getPackageName().equals("@ANDROID_PACKAGE_NAME@")) {
isGeckoActivityOpened = true;
mGeckoActivityOpened = true;
}
}
public boolean isGeckoActivityOpened() {
return mGeckoActivityOpened;
}
public boolean isApplicationInBackground() {
return !isGeckoActivityOpened;
return ((GeckoApplication) getApplication()).isApplicationInBackground();
}
}

View File

@ -11,6 +11,7 @@ import android.app.Application;
public class GeckoApplication extends Application {
private boolean mInBackground = false;
private ArrayList<ApplicationLifecycleCallbacks> mListeners;
public interface ApplicationLifecycleCallbacks {
@ -33,19 +34,21 @@ public class GeckoApplication extends Application {
}
public void onActivityPause(GeckoActivity activity) {
if (!activity.isApplicationInBackground())
if (activity.isGeckoActivityOpened())
return;
if (mListeners == null)
return;
mInBackground = true;
for (ApplicationLifecycleCallbacks listener: mListeners)
listener.onApplicationPause();
}
public void onActivityResume(GeckoActivity activity) {
// This is a misnomer. Should have been "wasApplicationInBackground".
if (!activity.isApplicationInBackground())
// This is a misnomer. Should have been "wasGeckoActivityOpened".
if (activity.isGeckoActivityOpened())
return;
if (mListeners == null)
@ -53,5 +56,11 @@ public class GeckoApplication extends Application {
for (ApplicationLifecycleCallbacks listener: mListeners)
listener.onApplicationResume();
mInBackground = false;
}
public boolean isApplicationInBackground() {
return mInBackground;
}
}