Listing case types and creating cases 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 environment by using Java. The tutorial explains how to use the Connect SDK Casetypes API to obtain a list of case types and also how to create a case.
The tutorial contains the following sections:
CaseTypesTab
and CaseCreationActivity
demo application classes that are part of the com.pega.helloconnectsdk
package.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 case types
You can use the Casetypes API to obtain a list of case types for the authenticated user.
- In the Android Studio environment, right-click the package where the new class is to be created, and click New > .
- Create a subclass of
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. - Name the class
CaseTypesTab
. This class is where all the logic that is related to obtaining case types for the Pega Platform application is placed. - Override its
onCreateView()
callback method so that you create an instance of theCaseTypeAdapter
class, which holds an array ofCaseType
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 theCaseTypesTab
class. Make a call togetAll()
for the Connect SDK Casetypes API to obtain a list of case types in the connected Pega Platform instance. Notice that thecaseTypes().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 case types is saved by using thesetData()
method in the instance of theCaseTypesAdapter
object.
Case type list - Casetypes API - You can now override the
onListItemClick()
method that is called when the user taps one of the case type names that are displayed. An instance of theCaseType
object is created to store the tapped case type. In addition, an instance of theCaseCreationActivity
object is created and started in the Android app. The app advances to the next screen, passing it the identifier of case type that was tapped. The next section describes how to create a case of the case type that was tapped.
Creating a case
The code developed in this section demonstrates how to create a case in your Android application by using the Casetypes API of the Connect SDK.
- In the Android Studio environment, right-click the package where the new class is to be created, and click
Activity
. Name the subclassCaseCreationActivity
. This class is where all the logic that is related to creating a new class of a selected type is placed. > . Create a subclass of - Override the
onCreate()
callback method, which is called when an instance of this class is called. Within this method, obtain the case type ID that was previously tapped by the user so that it can be used to create a new case in step 4. - Create a reference to the
onCreate()
listener method.Button createCase = (Button) findViewById(R.id.createCase);
button in the - Create an anonymous instance of the
View.OnClickListener()
class and, inside its overriddenonClick()
method, add Java code that allows the user to create a case of the current case type in the Android app when the button is clicked.The
cases().createCase()
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. Note that you pass the current case type ID to thecreateCase()
method, as its first parameter. The parent case ID is not used, so it is set to a null value, and finally, for the content we use the data that was entered in the key and value fields on the screen, respectively. ThecreateCase()
method'sonSuccess()
andonFailure()
callbacks let you define what to do when a new case is successfully created or not.
Create case - Case API