Class PushClient
Owns push registration and delivers typed push events to an application.
Create exactly one client from the application's init() method,
keep it in a field on the main application class, and call register()
from start(). Registration is idempotent, so it is safe for
start() to call it again when Codename One resumes the application.
Do not call unregister() from stop(); unregistering removes
the device subscription and is intended for an explicit user opt-out.
The listener is mandatory and is installed before native registration
starts. Messages that reach the runtime before register() are kept in
a bounded process-local queue and replayed when the client becomes active.
Native cold-start implementations also persist messages until the Codename
One runtime starts. All listener and registration-sink callbacks run on the
Codename One EDT.
Codename One does not discover a listener with reflection or
Class.forName(). Calling build() without a listener fails
immediately, but the application is responsible for retaining the client and
calling register(). Only one client can be active in a process.
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic PushClient.BuilderStarts a client builder for a managed BuildCloud push application.static voidDelivers an encoded schema-3 envelope from generated native code.static PushCallbackReturns the compatibility callback used by generated native bootstraps.getAppId()Returns the application key supplied tobuilder(String).Returns the latest native subscription reported by the transport.static booleanIndicates whether an active client can receive a native message now.voidregister()Activates this client and requests native push registration.voidRemoves this device's subscription.
-
Method Details
-
builder
Starts a client builder for a managed BuildCloud push application.
The application key is displayed in the Push section of the Codename One Console. It identifies the application during client registration; it is not a server API key. Install a
PushTransporton the returned builder to bypass BuildCloud and use an application-owned push server.- Parameters:
appId- the non-empty Push application key, or an application-owned identifier when using a custom transport- Returns:
- a new builder
- Throws:
IllegalArgumentException- ifappIdis null or empty
-
register
public void register()Activates this client and requests native push registration.
This method is idempotent. Calling it from each invocation of the application's
start()method requests registration only once. A native token persisted before this client becomes active is replayed immediately, then the platform is asked to refresh it. Registration otherwise completes asynchronously throughPushListener.onRegistration(PushSubscription)orPushListener.onError(PushError). Messages queued before activation are replayed before this method requests a new native token.If another
PushClientis already active, this client reports anactive_clienterror and remains inactive. -
unregister
public void unregister()Removes this device's subscription.
Use this for an explicit notification opt-out or account-removal workflow, not as part of the normal
stop()lifecycle. A later call toregister()may subscribe again after unregistration completes. Custom transports report completion throughPushTransport.Callback.unregistered(). -
getAppId
Returns the application key supplied tobuilder(String).- Returns:
- the application key
-
getSubscription
Returns the latest native subscription reported by the transport.- Returns:
- the current subscription, or
nullbefore registration or after unregistration
-
getActiveCallback
Returns the compatibility callback used by generated native bootstraps.
Application code should use
PushListener; this method exists for generated platform code and native transport integrations.- Returns:
- the active native callback, or
nullbefore a client is registered
-
hasActiveClient
public static boolean hasActiveClient()Indicates whether an active client can receive a native message now.- Returns:
trueafterregister()activates a client and before unregistration completes
-
dispatch
Delivers an encoded schema-3 envelope from generated native code.
If no client is active yet, the message is queued and replayed on the next successful
register(). Application code normally does not call this method; a customPushTransportshould use its callback'sPushTransport.Callback.message(String)method.- Parameters:
envelopeJson- the complete schema-3 JSON envelope
-