CLSActivity
A representation of user interaction with a context.
Declaration
class CLSActivityMentioned in
Overview
An activity represents a student’s attempt to complete the task corresponding to a CLSContext instance. For example, if a context represents a quiz, the associated activity represents the student’s attempt to take the quiz. As such, an activity is always associated with a context. You never initialize an activity in isolation or store a reference to it. Rather, you ask a context to create the activity and retrieve it from the context.
Starting and Stopping Activities
You start the activity with a call to the start() method when the user begins the task, and stop it with a call to the stop() method when the user finishes. You can also use the stop() method to stop it temporarily if the user pauses the task, in which case you can start it again later with another call to start() when the user resumes. The activity keeps track of the total time spent in the running state, which you can read via the duration property.
Whether you implement activity pausing depends on how the parts of your app work. For example, you might pause a game activity when the user presses the pause button to reflect that the user has stepped away from the activity, but is likely to return soon to complete the task. On the other hand, you might not provide a way to pause a quiz activity because you require that it be completed without interruption, once started. If you do pause, you can start and stop an activity as many times as you want, but when you create a new activity (representing a new attempt at a task), you can no longer access the older activity from your app.
Recording Progress
You can also assign progress to an activity. How you define progress depends on the task. For example, you can record progress through a quiz as a fraction of questions answered, or progress through a game level as a fraction of obstacles overcome.
To record additional metrics, you attach CLSActivityItem instances to an activity. For example, you can add both a score and a count of hints used to a quiz activity. To feature one of these items prominently, make it the primaryActivityItem.