Lightstreamer - Stock-List Demo - Android Kotlin Client
This project contains a full example of an Android application (Kotlin version) that employs the Lightstreamer Android Client library to subscribe to real-time updates. An equivalent version based on Java instead of Kotlin is available as well.
An extended version, including support for GCM push notifications (Java version) is also available: Stock-List Demo with GCM Push Notifications - Android Client
(To install the app from the Google Play Store, you can also use the above QR code)
This is a Kotlin-for-Android version of the Lightstreamer - Basic Stock-List Demo - HTML client.
This app uses the Android Client API for Lightstreamer to handle the communications with Lightstreamer Server. A simple user interface is implemented to display the real-time data received from Lightstreamer Server.
Touch a row opens a new panel with the detailed information, updated in real-time, of the stock.
Dig the Code
StockListDemoApplication.ktis the class representing the application itself. It creates and manage the LightstreamerClient instance that is shared by the other classes. A proxy to such instance is exposed as a singleton to the entire application.
StockListDemo.ktis the entry point and only
Activityof the application. It contains two
Fragments, the manu bar for the app and listens to LightstreamerClient status events to show the connection status to the user. The two
Fragmentare both visible if the application runs on tablet; on the contrary, only one
Fragmentis visible and are exchanged based on the user interaction
Fragmentcontaining a subscription that is started/stopped based on the lifecycle of the
Fragment. Please note that this class does not actually extend
DetailsFragment.ktare the classes representing the two fragments of the application.
Chart.ktwraps the AndroidPlot APIs to plot the real-time chart on the details fragment.
Check out the sources for further explanations.
NOTE: Not all the functionalities of the Lightstreamer Android Java client are exposed by the classes listed above. You can easily expand those functionalities using the Android Client API as a reference. If in trouble check out the specific Lightstreamer forum.
If you want to install a version of this demo pointing to your local Lightstreamer Server and running into an Android Virtual Device, follow these steps:
- Note that, as prerequisite, the Lightstreamer - Stock-List Demo - Java Adapter has to be deployed on your local Lightstreamer Server instance. Please check out that project and follow the installation instructions provided with it.
- Launch Lightstreamer Server.
- Download the
deploy.zipfile, which you can find in the deploy release of this project and extract the
- Locate or install the Android SDK
- Install the
Android_StockListDemo.apkin your emulator:
- Execute the emulator (Android SDK/SDK Manager->Tools->Manage AVDs...->New then Start)
- Open the console and move to the platform-tools folder of SDK directory.
- Then type the following command:
adb install [.apk path]
- Look up the demo in your virtual device and launch it.
Note that the demo targets the Lightstreamer server @ http://10.0.2.2:8080 because 10.0.2.2 is the special alias to your host loopback interface.
Setup the IDE
Note that you can skip this section and build the application without using any IDE.
To open the project in Android Studio, install Kotlin plugin (if missing), import the provided Gradle project.
You may run the demo against your local server or using our online server at http://push.lightstreamer.com:80. The server to which the demo will connect to is configured in the
In the former case, the example requires that the QUOTE_ADAPTER has to be deployed in your local Lightstreamer server instance;
the LiteralBasedProvider is also needed, but it is already provided by Lightstreamer server.
To build your own version of the demo you can launch the provided Gradle script from the command line or from the IDE itself. As an example you can build and install a debug version of the application in an emulator (or device) by running
You might also use a different build tool (e.g.: Maven, Ant, etc.) by converting the provided Gradle build files.
Lightstreamer Adapters Needed by This Demo Client
- Lightstreamer - Stock-List Demo - Java Adapter
- Lightstreamer - Reusable Metadata Adapters - Java Adapter
- Lightstreamer - Stock-List Demos - HTML Clients
- Lightstreamer - Stock-List Demo - Android Java Client
- Lightstreamer - Stock-List Demo with GCM Push Notifications - Android Client
Lightstreamer Compatibility Notes
- Compatible with Lightstreamer Android Client API v. 3.0 or newer.
- For Lightstreamer Allegro (+ Android Client API support), Presto, Vivace.
- For a version of this example compatible with Lightstreamer Android Client API version 2, please refer to this tag.
- For a version of this example compatible with Lightstreamer Android Client API version 1.1, please refer to this tag.