gecko/mobile/android/base/GeckoApplication.java
James Willcox 31cd926957 Bug 794642 - Avoid unnecessary GeckoApplication initialization in services r=kats
--HG--
extra : rebase_source : b406d8ee24c74b0185e9c31b15a4e6e20629d5f5
2012-09-27 10:52:59 -04:00

54 lines
1.7 KiB
Java

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko;
import android.app.Application;
import java.util.ArrayList;
public class GeckoApplication extends Application {
private boolean mInited;
private boolean mInBackground;
protected void initialize() {
if (mInited)
return;
// workaround for http://code.google.com/p/android/issues/detail?id=20915
try {
Class.forName("android.os.AsyncTask");
} catch (ClassNotFoundException e) {}
GeckoConnectivityReceiver.getInstance().init(getApplicationContext());
GeckoBatteryManager.getInstance().init(getApplicationContext());
GeckoBatteryManager.getInstance().start();
GeckoNetworkManager.getInstance().init(getApplicationContext());
MemoryMonitor.getInstance().init(getApplicationContext());
mInited = true;
}
protected void onActivityPause(GeckoActivity activity) {
mInBackground = true;
GeckoAppShell.sendEventToGecko(GeckoEvent.createPauseEvent(true));
GeckoConnectivityReceiver.getInstance().stop();
GeckoNetworkManager.getInstance().stop();
}
protected void onActivityResume(GeckoActivity activity) {
if (GeckoApp.checkLaunchState(GeckoApp.LaunchState.GeckoRunning))
GeckoAppShell.sendEventToGecko(GeckoEvent.createResumeEvent(true));
GeckoConnectivityReceiver.getInstance().start();
GeckoNetworkManager.getInstance().start();
mInBackground = false;
}
public boolean isApplicationInBackground() {
return mInBackground;
}
}