Listing assignments and their details with the Connect SDK on Android
This tutorial demonstrates how to configure and integrate the Connect SDK features with a new native Android application that was created in the Android Studio development environment by using Java. The tutorial shows how to use the Connect SDK Assignment API to obtain a list of assignments for a user and the details for a specific assignment.
AssignmentsTab
and AssignmentDetailsActivity
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 that is 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 assignments
You can use the Assignment API to obtain a list of assignments for a user.
In the Android Studio environment, right-click the package where the new class is to be created, and click
> .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
AssignmentsTab
. This class is where all the logic that is related to obtaining a list of assignments for the Pega Platform application is placed.Override its
onCreateView()
callback method so that you can create an instance of theAssignmentsAdapter
class, which holdsAssignmentInfo
objects for the application. Note that within this method you can also callupdate()
. The contents within this method are defined in the next step.Create the
update()
method for theAssignmentTab
class. Make a call togetAll()
for the Connect SDK Assignment API to obtain a list of assignments in the connected Pega Platform instance. Note that theassignments().getAll()
Connect SDK method is called on the previously obtainedPegaComponent
object. You obtain this by first getting an instance of thePegaSingleton
object by using thegetInstance()
method, and then calling thegetPega()
method on it. Notice that if successful, within theonSuccess()
callback, the data with all returned lists of assignments is saved using thesetData()
method in the instance of theAssignmentsAdapter
object. Within theonFailure()
callback, you display an error message when obtaining a list of assignments was not successful.
List of assignments - Assignment APIYou can now override the
onListItemClick()
method that is called when the user taps one of the assignments that are displayed. An instance of theAssignmentInfo
object is created to store the tapped assignment. In addition, an instance of theAssignmentDetailsActivity
object is created and started in the Android app. The app advances to the next screen, passing it the identifier of the assignment that was tapped on the screen. The next section describes how to display details for an assignment.
Obtaining assignment details
The Assignment API also provides the ability to obtain the details of an assignment after you obtain a list of assignments. You can use the identifier for an assignment to display its details. The following steps explain how to use the Connect SDK in your code for this purpose.
In the Android Studio environment, right-click the package where the new class is to be created, and click
> .Create a subclass of
Activity
. Name the subclassAssignmentDetailActivity
. This class is where all the logic that is related to the display of assignment details is placed.Override the
onCreate()
callback method, which is called when an instance of this class is called. Within this method, obtain the identifier of the assignment that was previously tapped by the user so that it can be used to display its details.Make a call to
assignments().getAssignment()
Connect SDK Assignment API on the previously obtainedPegaComponent
object, passing it the current assignment to obtain its details. You obtain this object by first getting an instance of thePegaSingleton
object by using thegetInstance()
method, and then calling thegetPega()
method on it. If successful in obtaining assignment details, within theonSuccess()
callback you display this information on the screen. If an error occurred, within theonFailure()
callback you display an error message.
Assignment details - Assignment API