Class Lifecycle
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCallback that can be overriden to disable or modify crash protectionvoiddestroy()Callback when the app is destroyedprotected FormReturns the form currently stored by thisLifecycleinstance for application resume handling.protected intReturns the default number of network thread countgetTheme()The theme instanceprotected StringReturns the name of the global theme file, by default it's "/theme".protected voidInvoked on a network error callbackvoidInvoked when the app is "cold launched", this acts like a constructorprotected voidonReady(boolean firstLaunch) Called once the application is on screen and#start()has returned: after the first launch and after every resume, as its own task on the EDT.voidonReceivedSharedContent(SharedContent content) Invoked when the app is launched or resumed because the user shared content (text, a URL, a file or an image) into it from another application.protected voidCalled by#start()when the application returns to the foreground with a form to return to.voidrunApp()Shows the first form of the application.protected voidsetCurrentForm(Form current) The current form within the application lifecycle which possibly differs from the one in the implementationvoidstart()Called by the OS on the first launch and every time the application comes back to the foreground: afterstop(), when the user taps a notification, or when another application (a provisioning flow, a share sheet, a payment app) brings this one forward.voidstop()Callback when the app is suspended
-
Constructor Details
-
Lifecycle
public Lifecycle()
-
-
Method Details
-
init
Invoked when the app is "cold launched", this acts like a constructor
Parameters
context: some OSs might pass a native object representing platform internal information
-
bindCrashProtection
protected void bindCrashProtection()Callback that can be overriden to disable or modify crash protection -
getNetworkThreadCount
protected int getNetworkThreadCount()Returns the default number of network thread count
Returns
currently two threads
-
getThemeName
Returns the name of the global theme file, by default it's "/theme". Can be overriden by subclasses to load a different file name
Returns
"/theme"
-
getTheme
The theme instance
Returns
the theme
-
handleNetworkError
Invoked on a network error callback
Parameters
err: the network error event
-
start
public void start()Called by the OS on the first launch and every time the application comes back to the foreground: after
stop(), when the user taps a notification, or when another application (a provisioning flow, a share sheet, a payment app) brings this one forward.Shows the form the application was on through
#onResume(Form)when there is one, and calls#runApp()otherwise. Either way it then schedules#onReady(boolean), which runs after this method has returned.Do not block here, or in
runApp()oronResume(Form), which run inside it: no modalDialog.show(),invokeAndBlock()orNetworkManager.addToQueueAndWait(). The OS expects this method to return, and a push can arrive while it is blocked. The simulator throws acom.codename1.ui.BlockingDisallowedExceptionfor a blocking call made here so the mistake is found at the line that makes it. Put such code inonReady(boolean). -
runApp
public void runApp()Shows the first form of the application. Called by
#start()when there is no form to return to: on the first launch, and on a later start whenstop()found none.It runs inside
start(), so it must not block; see#start(). Build and show the form here, and do anything that waits -- a login check against the server, an SDK that shows its own dialog, a permission prompt -- in#onReady(boolean). -
onResume
Called by
#start()when the application returns to the foreground with a form to return to. The default showscurrentagain. Override it to refresh what that form shows, or to route somewhere else, for example back to a login form after a timeout.It runs inside
start(), so it must not block; see#start().Parameters
current: the form that was showing when the application was stopped
-
onReady
protected void onReady(boolean firstLaunch) Called once the application is on screen and
#start()has returned: after the first launch and after every resume, as its own task on the EDT.This is the place for startup work that waits or shows something on top of the form: validation dialogs, a backend or SDK call, re-authentication when the application returns. Blocking calls are allowed here. Pushes that arrive while such a call is in progress are held until it returns (see
com.codename1.push.Push#setDeliveryDeferred(boolean)), so apush()callback does not run in the middle of it.The default does nothing.
Parameters
firstLaunch: true the first time after the application process started, false on a resume
-
stop
public void stop()Callback when the app is suspended -
destroy
public void destroy()Callback when the app is destroyed -
getCurrentForm
Returns the form currently stored by this
Lifecycleinstance for application resume handling.In most application code, use
CN.getCurrentForm()instead, as it returns the form that is actually displayed on the screen. This method is only useful when subclassingLifecycleand you need to inspect or customize the form remembered bystop()and restored bystart(), which may differ from the form currently displayed by the Codename One implementation.Returns
the form stored in this lifecycle, or
nullif no form has been stored -
setCurrentForm
The current form within the application lifecycle which possibly differs from the one in the implementation
Parameters
current: the new current Form
-