The entry point of Firebase SDKs. It holds common configuration and state for Firebase APIs. Most applications don't need to directly interact with FirebaseApp.
Firebase APIs use the default FirebaseApp by default, unless a different one is explicitly passed to the API via FirebaseFoo.getInstance(firebaseApp).
The default app instance is initialized on app startup by
FirebaseInitProvider. This is added to the app's manifest by
Gradle manifest merging. If the app is using a different build system the provider needs to be
manually added to the app's manifest.
Alternatively initializeApp(Context, FirebaseOptions) initializes the default
app instance. This method should be invoked from Application. This is also
necessary if it is used outside of the application's main process.
Constant Summary
| String | DEFAULT_APP_NAME |
Public Method Summary
| boolean | |
| Context |
getApplicationContext()
Returns the application
Context. |
| static List<FirebaseApp> | |
| static FirebaseApp |
getInstance(String name)
Returns the instance identified by the unique name, or throws if it does not exist.
|
| static FirebaseApp |
getInstance()
Returns the default (first initialized) instance of the
FirebaseApp. |
| String |
getName()
Returns the unique name of this app.
|
| FirebaseOptions |
getOptions()
Returns the specified
FirebaseOptions. |
| int |
hashCode()
|
| static FirebaseApp |
initializeApp(Context context, FirebaseOptions options)
Initializes the default
FirebaseApp instance. |
| static FirebaseApp |
initializeApp(Context context, FirebaseOptions options, String name)
A factory method to intialize a
FirebaseApp. |
| static FirebaseApp |
initializeApp(Context context)
Initializes the default FirebaseApp instance using string resource values -
populated from google-services.json.
|
| void |
setAutomaticResourceManagementEnabled(boolean enabled)
If set to true it indicates that Firebase should close database connections automatically
when the app is in the background.
|
| String |
toString()
|
Inherited Method Summary
Constants
Public Methods
public static List<FirebaseApp> getApps (Context context)
Returns a mutable list of all FirebaseApps.
public static FirebaseApp getInstance (String name)
Returns the instance identified by the unique name, or throws if it does not exist.
Parameters
| name | represents the name of the FirebaseApp instance. |
|---|
Throws
| IllegalStateException | if the FirebaseApp was not initialized, either via
initializeApp(Context, FirebaseOptions, String).
|
|---|
public static FirebaseApp getInstance ()
Returns the default (first initialized) instance of the FirebaseApp.
Throws
| IllegalStateException | if the default app was not initialized. |
|---|
public FirebaseOptions getOptions ()
Returns the specified FirebaseOptions.
public int hashCode ()
public static FirebaseApp initializeApp (Context context, FirebaseOptions options)
Initializes the default FirebaseApp instance. Same as
initializeApp(Context, FirebaseOptions), but it uses DEFAULT_APP_NAME as
name.
The creation of the default instance is automatically triggered at app startup time, if Firebase configuration values are available from resources - populated from google-services.json.
public static FirebaseApp initializeApp (Context context, FirebaseOptions options, String name)
A factory method to intialize a FirebaseApp.
Parameters
| context | represents the Context |
|---|---|
| options | represents the global FirebaseOptions |
| name | unique name for the app. It is an error to initialize an app with an already existing name. Starting and ending whitespace characters in the name are ignored (trimmed). |
Returns
- an instance of
FirebaseApp
Throws
| IllegalStateException | if an app with the same name has already been initialized. |
|---|
public static FirebaseApp initializeApp (Context context)
Initializes the default FirebaseApp instance using string resource values - populated from google-services.json. It also initializes Firebase Analytics for the current process.
This method is called at app startup time by
FirebaseInitProvider. Call this method before any
Firebase APIs in components outside the main process.
The FirebaseOptions values used by the default app instance are read
from string resources.
Returns
- the default FirebaseApp, if either it has been initialized previously, or Firebase API keys are present in string resources. Returns null otherwise.
public void setAutomaticResourceManagementEnabled (boolean enabled)
If set to true it indicates that Firebase should close database connections automatically when the app is in the background. Disabled by default.

