public class

Goal

extends Object
implements Parcelable
java.lang.Object
   ↳ com.google.android.gms.fitness.data.Goal

Class Overview

A fitness goal, which users create in Google Fit.

A goal should hold its objective, time period and activity (if any).

There are different objective types:

  • Goal.MetricObjective uses a metric value to determine whether the goal is met. Metrics include step, distance and calories. e.g. Take 10k steps.
  • Goal.DurationObjective uses duration time of activities to determine whether the goal is met. e.g. Run 30 minutes.
  • Goal.FrequencyObjective uses the number of activity segments to determine whether the goal is met. e.g. Do yoga 2x.

A goal also has a recurrence period, since users often want to "take 10k steps a day" or "do yoga 2x per week".

A goal holds different times:

  • create time is the time when a goal was first created.
  • start time is the start of the time range that should be used to calculate a goal's progress for current recurrence period. For a weekly goal, this will be the start of the current week.
  • end time is the end of the time range that should be used to calculate a goal's progress for current recurrence period. For a daily goal, this will be the end of the current day.
The following are some common goals:
Goal Recurrence Activity Objective type Objective
Run 3 times a week. 1 week RUNNING OBJECTIVE_TYPE_FREQUENCY Frequency: 3
Active 60 minutes a day. 1 day N/A OBJECTIVE_TYPE_DURATION Duration: 60 minutes
Take 1,000 steps a day. 1 day N/A OBJECTIVE_TYPE_METRIC
  • DataType: TYPE_STEP_COUNT_DELTA
  • Value: 1,000
  • Run 2 km a week. 1 week RUNNING OBJECTIVE_TYPE_METRIC
  • DataType: TYPE_DISTANCE_DELTA
  • Value: 2,000
  • Burn 30k calories a month. 1 month N/A OBJECTIVE_TYPE_METRIC
  • DataType: TYPE_CALORIES_EXPENDED
  • Value: 30,000
  • Summary

    Nested Classes
    class Goal.DurationObjective A duration objective, which uses duration time of activities to determine whether the goal is met. 
    class Goal.FrequencyObjective A frequency objective, which uses the number of activity segments to determine whether the goal is met. 
    class Goal.MetricObjective A metric objective, which uses a metric value to determine whether the goal is met. 
    class Goal.MismatchedGoalException Exception thrown by getMetricObjective(), getDurationObjective(), getFrequencyObjective() if the goal doesn't match the requested objective type. 
    @interface Goal.ObjectiveType Type of a goal's objective. 
    class Goal.Recurrence A recurrence period of a recurring goal. 
    Constants
    int OBJECTIVE_TYPE_DURATION Objective type constant representing a duration objective, which uses duration time of activities to determine whether the goal is met.
    int OBJECTIVE_TYPE_FREQUENCY Objective type constant representing a frequency objective, which uses the number of activity segments to determine whether the goal is met.
    int OBJECTIVE_TYPE_METRIC Objective type constant representing a metric objective, which uses a metric value to determine whether the goal is met.
    [Expand]
    Inherited Constants
    From interface android.os.Parcelable
    Fields
    public static final Creator<Goal> CREATOR
    Public Methods
    boolean equals(Object that)
    String getActivityName()
    Returns the name of the goal's specific activity, if any.
    long getCreateTime(TimeUnit timeUnit)
    Returns the creation time of the goal since epoch, in the specified time unit.
    Goal.DurationObjective getDurationObjective()
    Returns the duration objective of the goal if the objective type is OBJECTIVE_TYPE_DURATION.
    long getEndTime(Calendar current, TimeUnit timeUnit)
    Returns the end time of the time range that should be used to calculate goal progress for current time.
    Goal.FrequencyObjective getFrequencyObjective()
    Returns the frequency objective of the goal if the objective type is OBJECTIVE_TYPE_FREQUENCY.
    Goal.MetricObjective getMetricObjective()
    Returns the metric objective of the goal if the objective type is OBJECTIVE_TYPE_METRIC.
    int getObjectiveType()
    Returns the type of the goal's objective.
    Goal.Recurrence getRecurrence()
    Returns the recurrence period of a goal if the goal is a recurring one.
    long getStartTime(Calendar current, TimeUnit timeUnit)
    Returns the start time of the time range that should be used to calculate goal progress for current time.
    int hashCode()
    String toString()
    void writeToParcel(Parcel dest, int flags)
    [Expand]
    Inherited Methods
    From class java.lang.Object
    From interface android.os.Parcelable

    Constants

    public static final int OBJECTIVE_TYPE_DURATION

    Objective type constant representing a duration objective, which uses duration time of activities to determine whether the goal is met. e.g. Run 30 minutes.

    Constant Value: 2 (0x00000002)

    public static final int OBJECTIVE_TYPE_FREQUENCY

    Objective type constant representing a frequency objective, which uses the number of activity segments to determine whether the goal is met. e.g. Do yoga 2x.

    Constant Value: 3 (0x00000003)

    public static final int OBJECTIVE_TYPE_METRIC

    Objective type constant representing a metric objective, which uses a metric value to determine whether the goal is met. e.g. Take 10k steps.

    Constant Value: 1 (0x00000001)

    Fields

    public static final Creator<Goal> CREATOR

    Public Methods

    public boolean equals (Object that)

    Parameters
    that Object
    Returns
    boolean

    public String getActivityName ()

    Returns the name of the goal's specific activity, if any. e.g. Returns "running" for a goal "run 30km a week".

    Returns
    String null if there is no specific activity for the goal. If there is no specific activity for a goal, then the goal should apply to all activities. e.g. The goal "30km a week" takes into account all activities including walking, running, biking, etc.

    public long getCreateTime (TimeUnit timeUnit)

    Returns the creation time of the goal since epoch, in the specified time unit.

    Parameters
    timeUnit TimeUnit
    Returns
    long

    public Goal.DurationObjective getDurationObjective ()

    Returns the duration objective of the goal if the objective type is OBJECTIVE_TYPE_DURATION.

    Returns
    Goal.DurationObjective
    Throws
    Goal.MismatchedGoalException if the objective type of the goal is not OBJECTIVE_TYPE_DURATION

    public long getEndTime (Calendar current, TimeUnit timeUnit)

    Returns the end time of the time range that should be used to calculate goal progress for current time. For recurring goals, end time represents the end time of the current recurrence of the goal. For non-recurring goals, the end time is the time at which user activities stop counting towards the objective.

    Parameters
    current Calendar: current time
    timeUnit TimeUnit: the desired time unit for the returned end time
    Returns
    long

    public Goal.FrequencyObjective getFrequencyObjective ()

    Returns the frequency objective of the goal if the objective type is OBJECTIVE_TYPE_FREQUENCY.

    Returns
    Goal.FrequencyObjective
    Throws
    Goal.MismatchedGoalException if the objective type of the goal is not OBJECTIVE_TYPE_FREQUENCY

    public Goal.MetricObjective getMetricObjective ()

    Returns the metric objective of the goal if the objective type is OBJECTIVE_TYPE_METRIC.

    Returns
    Goal.MetricObjective
    Throws
    Goal.MismatchedGoalException if the objective type of the goal is not OBJECTIVE_TYPE_METRIC

    public int getObjectiveType ()

    Returns the type of the goal's objective. The objective type should be one of the OBJECTIVE_TYPE_METRIC, OBJECTIVE_TYPE_DURATION, OBJECTIVE_TYPE_FREQUENCY constants.

    Returns
    int

    public Goal.Recurrence getRecurrence ()

    Returns the recurrence period of a goal if the goal is a recurring one. e.g. Returns 1 week for a goal to "run 30km a week".

    Returns
    Goal.Recurrence null if the goal is not recurring.

    public long getStartTime (Calendar current, TimeUnit timeUnit)

    Returns the start time of the time range that should be used to calculate goal progress for current time. This is the time from which user activities start counting towards the objective. For recurring goals, start time represents the start time of the current recurrence of the goal. For non-recurring goals, start time is the same as create time.

    Parameters
    current Calendar: current time
    timeUnit TimeUnit: the desired time unit for the returned start time
    Returns
    long

    public int hashCode ()

    Returns
    int

    public String toString ()

    Returns
    String

    public void writeToParcel (Parcel dest, int flags)

    Parameters
    dest Parcel
    flags int