Listing cases and their details with the Connect SDK on Android
This tutorial demonstrates how to configure and integrate the Connect SDK features with a new Android application that was created in the Android Studio development environment using the Java language. The tutorial also explains how to use the Connect SDK Cases API to obtain a list of cases for a user and also to display the specific case details in the Android app.
The tutorial contains the following sections:
Prerequisites
Before you start this tutorial, do the following tasks:
- Read Creating a Hello World Android app with the Connect SDK, which describes how to set up the Connect SDK in the Android Studio environment, initialize it, and use it to authenticate.
- Download ConnectSDKDemo.zip, which contains the sample Java code and other Android Studio project files for the Android app described in this tutorial.
You can connect to any Pega® Platform instance to test the Android app. Make sure that it already includes some cases and assignments.
Obtaining a list of cases
You can use the Cases API to obtain a list of cases for the Pega Platform application.
- In the Android Studio environment, right-click the package where the new class is to be created, and click
ListFragment
. You must use aFragmentTabHost
class, a specialTabHost
that allows the use ofFragment
objects for its tab content. For more information, consult theTabsActivity.java
file for the included sample project and the Android developer guide. > . Create a subclass of - Name the class
CasesTab
. This subclass is where all the logic that is related to obtaining a list of cases for a Pega Platform application is placed. - Override its
onCreateView()
callback method so that you create an instance ofCasesAdapter
class, which holds an array ofCaseInfo
objects for the application. Notice that within this method you also callupdate()
. This method is defined in the next step. - Create the
update()
method for theCasesTab
class. Make a call togetAll()
for the Connect SDK Cases API to obtain a list of cases in the connected Pega Platform instance. Notice that thecases().getAll()
Connect SDK method is called on the previously obtainedPegaComponent
object. You obtain this object by first getting an instance of thePegaSingleton
object by using thegetInstance()
method, and then calling thegetPega()
method on it. The data for all returned cases is saved by using thesetData()
method in the instance of theCaseAdapter
object. - You can now override the
onListItemClick()
method that is called when the user clicks one of the case names that is displayed. An instance of theCaseInfo
object is created to store the case details. In addition, an instance of theCaseDetailsActivity
object is created and started in the Android app. The app advances to the next screen, passing the identifier, name, status, and urgency of the single case that was clicked. The next section describes how to obtain these case details that were passed by using the Connect SDK Cases API and display it on the screen.
Obtaining case details
After you receive a list of cases, you can add the Java code that obtains the details for a particular case based on its identifier.
- In the Android Studio environment, right-click the package where the new class is to be created, and click
ListFragment
. You must use aFragmentTabHost
class, a specialTabHost
that allows the use ofFragment
objects for its tab content. For more information, consult theTabsActivity.java
file for the included sample project and the Android developer guide. > . Create a subclass of - Name the class
CasesTab
. This subclass is where all the logic that is related to obtaining a list of cases for a Pega Platform application is placed. - Override its
onCreateView()
callback method so that you create an instance ofCasesAdapter
class, which holds an array ofCaseInfo
objects for the application. Notice that within this method you also callupdate()
. This method is defined in the next step. - Create the
update()
method for theCasesTab
class. Make a call togetAll()
for the Connect SDK Cases API to obtain a list of cases in the connected Pega Platform instance. Notice that thecases().getAll()
Connect SDK method is called on the previously obtainedPegaComponent
object. You obtain this object by first getting an instance of thePegaSingleton
object by using thegetInstance()
method, and then calling thegetPega()
method on it. The data for all returned cases is saved by using thesetData()
method in the instance of theCaseAdapter
object. - You can now override the
onListItemClick()
method that is called when the user clicks one of the case names that is displayed. An instance of theCaseInfo
object is created to store the case details. In addition, an instance of theCaseDetailsActivity
object is created and started in the Android app. The app advances to the next screen, passing the identifier, name, status, and urgency of the single case that was clicked. The next section describes how to obtain these case details that were passed by using the Connect SDK Cases API and display it on the screen.