firebase::App

#include <app.h>

Firebase application object.

Summary

firebase::App acts as a conduit for communication between all Firebase services used by an application.

For example:

#if defined(__ANDROID__)firebase::App::Create(firebase::AppOptions(),jni_env,activity);#elsefirebase::App::Create(firebase::AppOptions());#endif// defined(__ANDROID__)

Constructors and Destructors

~App()

Public functions

GetJNIEnv() const
JNIEnv *
Get JNI environment, needed for performing JNI calls, set on creation.
activity() const
jobject
Get a global reference to the Android activity provided to theApp on creation.
java_vm() const
JavaVM *
Get Java virtual machine, retrieved from the initial JNI environment.
name() const
const char *
Get the name of thisApp instance.
options() const
constAppOptions &
Get options theApp was created with.

Public static functions

Create()
App *
Initializes the defaultfirebase::App with default options.
Create(JNIEnv *jni_env, jobject activity)
App *
Initializes the defaultfirebase::App with default options.
Create(constAppOptions & options)
App *
Initializes the defaultfirebase::App with the given options.
Create(constAppOptions & options, JNIEnv *jni_env, jobject activity)
App *
Initializes the defaultfirebase::App with the given options.
Create(constAppOptions & options, const char *name)
App *
Initializes afirebase::App with the given options that operates on the named app.
Create(constAppOptions & options, const char *name, JNIEnv *jni_env, jobject activity)
App *
Initializes afirebase::App with the given options that operates on the named app.
GetApps()
std::vector<App * >
Get all the apps, including the default one.
GetInstance()
App *
Get the defaultApp, or nullptr if none has been created.
GetInstance(const char *name)
App *
Get theApp with the given name, or nullptr if none have been created.

Public functions

GetJNIEnv

JNIEnv*GetJNIEnv()const

Get JNI environment, needed for performing JNI calls, set on creation.

This is not trivial as the correct environment needs to retrieved per thread.Note: This method is specific to the Android implementation.

Details
Returns
JNI environment object.

activity

jobjectactivity()const

Get a global reference to the Android activity provided to theApp on creation.

Also serves as the Context needed for Firebase calls.Note: This method is specific to the Android implementation.

Details
Returns
Global JNI reference to the Android activity used to create theApp. The reference count of the returned object is not increased.

name

constchar*name()const

Get the name of thisApp instance.

Details
Returns
The name of thisApp instance. If a name wasn't provided viaCreate(), this returnskDefaultAppName.

options

constAppOptions&options()const

Get options theApp was created with.

Details
Returns
Options used to create theApp.

~App

~App()

Public static functions

Create

App*Create()

Initializes the defaultfirebase::App with default options.

Note: This method is specific to non-Android implementations.

Details
Returns
NewApp instance, theApp should not be destroyed for the lifetime of the application. If default options can't be loaded this will return null.

Create

App*Create(JNIEnv*jni_env,jobjectactivity)

Initializes the defaultfirebase::App with default options.

Note: This method is specific to the Android implementation.

Details
Parameters
jni_env
JNI environment required to allow Firebase services to interact with the Android framework.
activity
JNI reference to the Android activity, required to allow Firebase services to interact with the Android application.
Returns
NewApp instance. TheApp should not be destroyed for the lifetime of the application. If default options can't be loaded this will return null.

Create

App*Create(constAppOptions&options)

Initializes the defaultfirebase::App with the given options.

Note: This method is specific to non-Android implementations.Options are copied at initialization time, so changes to the object are ignored.

Details
Parameters
options
Options that control the creation of theApp.
Returns
NewApp instance, theApp should not be destroyed for the lifetime of the application.

Create

App*Create(constAppOptions&options,JNIEnv*jni_env,jobjectactivity)

Initializes the defaultfirebase::App with the given options.

Note: This method is specific to the Android implementation.Options are copied at initialization time, so changes to the object are ignored.

Details
Parameters
options
Options that control the creation of theApp.
jni_env
JNI environment required to allow Firebase services to interact with the Android framework.
activity
JNI reference to the Android activity, required to allow Firebase services to interact with the Android application.
Returns
NewApp instance. TheApp should not be destroyed for the lifetime of the application.

Create

App*Create(constAppOptions&options,constchar*name)

Initializes afirebase::App with the given options that operates on the named app.

Note: This method is specific to non-Android implementations.Options are copied at initialization time, so changes to the object are ignored.

Details
Parameters
options
Options that control the creation of theApp.
name
Name of thisApp instance. This is only required when one application uses multipleApp instances.
Returns
NewApp instance, theApp should not be destroyed for the lifetime of the application.

Create

App*Create(constAppOptions&options,constchar*name,JNIEnv*jni_env,jobjectactivity)

Initializes afirebase::App with the given options that operates on the named app.

Note: This method is specific to the Android implementation.Options are copied at initialization time, so changes to the object are ignored.

Details
Parameters
options
Options that control the creation of theApp.
name
Name of thisApp instance. This is only required when one application uses multipleApp instances.
jni_env
JNI environment required to allow Firebase services to interact with the Android framework.
activity
JNI reference to the Android activity, required to allow Firebase services to interact with the Android application.
Returns
NewApp instance. TheApp should not be destroyed for the lifetime of the application.

GetApps

std::vector<App*>GetApps()

Get all the apps, including the default one.

GetInstance

App*GetInstance()

Get the defaultApp, or nullptr if none has been created.

GetInstance

App*GetInstance(constchar*name)

Get theApp with the given name, or nullptr if none have been created.

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 2024-01-23 UTC.