FirebaseApp

public classFirebaseApp


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.

For a vast majority of apps,FirebaseInitProvider will handle the initialization of Firebase for the default project that it's configured to work with, via the data contained in the app'sgoogle-services.json file. This ContentProvider is merged into the app's manifest by default when building with Gradle, and it runs automatically at app launch.No additional lines of code are needed in this case.

In the event that an app requires access to another Firebase projectin addition to the default project,initializeApp must be used to create that relationship programmatically. The name parameter must be unique. To connect to the resources exposed by that project, use theFirebaseApp object returned bygetInstance, passing it the same name used with initializeApp. This object must be passed to the static accessor of the feature that provides the resource. For example, getInstance is used to access the storage bucket provided by the additional project, whereas getInstance is used to access the default project.

AnyFirebaseApp initialization must occur only in the main process of the app. Use of Firebase in processes other than the main process is not supported and will likely cause problems related to resource contention.

Summary

Constants

static final @NonNullString
DEFAULT_APP_NAME = "[DEFAULT]"

Public methods

boolean
@NonNullContext

Returns the applicationContext.

static @NonNullList<FirebaseApp>

Returns a mutable list of all FirebaseApps.

static @NonNullFirebaseApp

Returns the default (first initialized) instance of theFirebaseApp.

static @NonNullFirebaseApp

Returns the instance identified by the unique name, or throws if it does not exist.

@NonNullString

Returns the unique name of this app.

@NonNullFirebaseOptions

Returns the specifiedFirebaseOptions.

int
static @NullableFirebaseApp

Initializes the default FirebaseApp instance using string resource values - populated from google-services.json.

static @NonNullFirebaseApp

Initializes the defaultFirebaseApp instance.

static @NonNullFirebaseApp
initializeApp(
    @NonNullContext context,
    @NonNullFirebaseOptions options,
    @NonNullString name
)

A factory method to initialize aFirebaseApp.

void

If set to true it indicates that Firebase should close database connections automatically when the app is in the background.

String

Constants

DEFAULT_APP_NAME

public static final @NonNullString DEFAULT_APP_NAME = "[DEFAULT]"

Public fields

applicationContext

public final Context applicationContext

name

public final String name

options

public final FirebaseOptions options

Public methods

equals

public boolean equals(Object o)

getApplicationContext

public @NonNullContext getApplicationContext()

Returns the applicationContext.

getApps

public static @NonNullList<FirebaseAppgetApps(@NonNullContext context)

Returns a mutable list of all FirebaseApps.

getInstance

public static @NonNullFirebaseApp getInstance()

Returns the default (first initialized) instance of theFirebaseApp.

Throws
java.lang.IllegalStateException java.lang.IllegalStateException

if the default app was not initialized.

getInstance

public static @NonNullFirebaseApp getInstance(@NonNullString name)

Returns the instance identified by the unique name, or throws if it does not exist.

Parameters
@NonNullString name

represents the name of theFirebaseApp instance.

Throws
java.lang.IllegalStateException java.lang.IllegalStateException

if theFirebaseApp was not initialized, either viainitializeApp.

getName

public @NonNullString getName()

Returns the unique name of this app.

getOptions

public @NonNullFirebaseOptions getOptions()

Returns the specifiedFirebaseOptions.

hashCode

public int hashCode()

initializeApp

public static @NullableFirebaseApp initializeApp(@NonNullContext 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 byFirebaseInitProvider. Call this method before any Firebase APIs in components outside the main process.

TheFirebaseOptions values used by the default app instance are read from string resources.

Returns
@NullableFirebaseApp

the default FirebaseApp, if either it has been initialized previously, or Firebase API keys are present in string resources. Returns null otherwise.

initializeApp

public static @NonNullFirebaseApp initializeApp(@NonNullContext context, @NonNullFirebaseOptions options)

Initializes the defaultFirebaseApp instance. Same asinitializeApp, but it usesDEFAULT_APP_NAME as name.

It's only required to call this to initialize Firebase if it'snot possible to do so automatically inFirebaseInitProvider. Automatic initialization that way is the expected situation.

initializeApp

public static @NonNullFirebaseApp initializeApp(
    @NonNullContext context,
    @NonNullFirebaseOptions options,
    @NonNullString name
)

A factory method to initialize aFirebaseApp.

Parameters
@NonNullContext context

represents theContext

@NonNullFirebaseOptions options

represents the globalFirebaseOptions

@NonNullString 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
@NonNullFirebaseApp

an instance ofFirebaseApp

Throws
java.lang.IllegalStateException java.lang.IllegalStateException

if an app with the same name has already been initialized.

setAutomaticResourceManagementEnabled

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.

toString

public String toString()

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-21 UTC.