Skip to main content

PortalManager

The PortalManager object is used to create a and manage multiple Portal instances. It follows a Singleton Pattern to allow access to any Portal from anywhere in the application. PortalManager can be used in situations where you want to programmatically create a Portal at runtime rather than defining it via XML. An example of how to create a Portal using the PortalManager class is directly below.

PortalManager.newPortal("my_portal")
.addPlugin(MyCapacitorPlugin::class.java)
.setPortalFragmentType(MyFadeInOutPortalFragment::class.java)
.setInitialContext(mapOf("myVariableFromAndroid" to 42))
.setStartDir("web_app")
.create()

Methods

addPortal

static

Add an existing Portal to the PortalManager object. This is not neccessary if the Portal is created via the PortalManager.newPortal() function.

Usage

val portal: Portal = someValue
PortalManager.addPortal(portal)

Parameters

NameTypeDescription
portalPortalAn existing Portal to add to the PortalManager.

getPortal

static

Gets an existing Portal on the PortalManager object. This function will throw an IllegalStateException if the Portal is not found.

Usage

val portal: Portal = PortalManager.getPortal("my_portal")

Parameters

NameTypeDescription
nameStringThe Portal name to look up in the PortalManager object.

Returns: Portal

size

static

Returns the number of Portal instances managed by the PortalManager object.

Usage

val portalCount: Int = PortalManager.size()

Parameters

NameTypeDescription
nameStringThe Portal name to look up in the PortalManager object.

Returns: Int

newPortal

static

A function to create a PortalBuilder class and, after building, add it to the PortalManager. Classes built with the PortalManager.newPortal()` function are added to the PortalManager automatically.

Usage

val builder: PortalBuilder = PortalManager.newPortal("my_portal")
val portal: Portal = builder.create()

Parameters

NameTypeDescription
nameStringThe Portal name to create.

Returns: Portal

register

static

A function to validate the registration of the Ionic Portals instance with your API Key. This function will work offline and only needs to be run once before creating your first Portal

caution

Avoid committing your Portals key to source code repositories where it may be publicly visible! On Android, you can use the Secrets Gradle Plugin to keep it out of a public repository.

Usage

PortalManager.register("YOUR_PORTALS_KEY")

Parameters

NameTypeDescription
keyStringThe Portal API Key to register.