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.
- Kotlin
- Java
PortalManager.newPortal("my_portal")
.addPlugin(MyCapacitorPlugin::class.java)
.setPortalFragmentType(MyFadeInOutPortalFragment::class.java)
.setInitialContext(mapOf("myVariableFromAndroid" to 42))
.setStartDir("web_app")
.create()
PortalManager.newPortal("my_portal")
.addPlugin(MyCapacitorPlugin.class)
.setPortalFragmentType(MyFadeInOutPortalFragment.class)
.setInitialContext(Map.of("myVariableFromAndroid", 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
- Kotlin
- Java
val portal: Portal = someValue
PortalManager.addPortal(portal)
Portal portal = someValue
PortalManager.addPortal(portal)
Parameters
Name | Type | Description |
---|---|---|
portal | Portal | An 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
- Kotlin
- Java
val portal: Portal = PortalManager.getPortal("my_portal")
Portal portal = PortalManager.getPortal("my_portal");
Parameters
Name | Type | Description |
---|---|---|
name | String | The 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
- Kotlin
- Java
val portalCount: Int = PortalManager.size()
int portalCount = PortalManager.size();
Parameters
Name | Type | Description |
---|---|---|
name | String | The 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
- Kotlin
- Java
val builder: PortalBuilder = PortalManager.newPortal("my_portal")
val portal: Portal = builder.create()
PortalBuilder builder = PortalManager.newPortal("my_portal");
Portal portal = builder.create();
Parameters
Name | Type | Description |
---|---|---|
name | String | The 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
- Kotlin
- Java
PortalManager.register("YOUR_PORTALS_KEY")
PortalManager.register("YOUR_PORTALS_KEY");
Parameters
Name | Type | Description |
---|---|---|
key | String | The Portal API Key to register. |