With so many advanced frameworks baked in the Foundation, Crosslight provides application services that streamline the life cycle of the mobile apps. More importantly, the application services and life cycle work consistently and reliably across the supported mobile platforms regardless of their design differences. This allows you to write application logic in respond to the life cycle changes – all from within the shared application layer. For instances, you can write code that save certain data state when the application has stopped, or navigates to a specific screen when the application resumes.
The Crosslight application service consisted of a number of methods that you can implement to provide custom logic in respond to certain life cycle changes such as OnStart, OnPause, OnResume, OnTerminate and more.
In addition, you can get the running application context from the application service which provides a host of useful information related to the application, the platform operating system, and the device. With the application context accessible from the shared application layer, you can write sophisticated user interaction logic based on complex conditions that take account the device kind, the platform operating system, and much more.
The following diagram illustrates the application life cycle in Crosslight, and the dependency relationship between the core assembly and the platform-specific assembly.
A Crosslight application is powered by an application service instance which is typically defined in the shared application assembly – further referred as core assembly. The application service – named as MyAppService for instance – is then consumed in each native platform assembly when the application is initialized. This architectural design allows Crosslight to take full control on the application life cycle by seamlessly calling the respective implementation of MyAppService.
At the most minimum, you will need to implement the OnStart method of your application service to specify the root ViewModel used in the application. The root ViewModel determines the initial screen to display as the application starts.
The following code example shows the implementation of application service that resides in the core project.
The following code example shows the consumption of the application service in the platform-specific project when the application is initializing.
The application service implementation itself conforms to the IApplicationService Interface which contains a number of members that you might be interested to implement.