Session.Builder
Stay organized with collections
Save and categorize content based on your preferences.
Builder used to create new Sessions.
Public Constructor Summary
Inherited Method Summary
From class java.lang.Object
Public Methods
public Session
build
()
Finishes building and returns the session. Returned session will always have
non-empty non-null identifier.
Throws
If the builder doesn't have enough state to create a valid request.
Sets the active session period duration.
Sets the activity associated with this session. The specified activity value should
be one of the values in FitnessActivities
.
If an unrecognized value is specified, or if not specified, the activity for the
session is set to FitnessActivities.UNKNOWN
.
Sets a description for this session.
Sets the end time of the session. If end time is not specified, session is
considered to be still ongoing.
Parameters
Sets the identifier for this session. Must be unique for the client application.
Sets the a human readable name of the session.
Sets the start time of the session.
Parameters
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eSession.Builder\u003c/code\u003e is used to create new fitness sessions within a client application.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods to set session attributes like activity type, description, start and end times, identifier, and name.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ebuild()\u003c/code\u003e method creates a \u003ccode\u003eSession\u003c/code\u003e object from the builder, requiring a valid state to avoid exceptions.\u003c/p\u003e\n"],["\u003cp\u003eActive time can be specified using \u003ccode\u003esetActiveTime()\u003c/code\u003e, representing the duration of the session.\u003c/p\u003e\n"],["\u003cp\u003eSession identifier must be unique within the client application, ensuring session distinction.\u003c/p\u003e\n"]]],[],null,["# Session.Builder\n\npublic static class **Session.Builder** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nBuilder used to create new Sessions. \n\n### Public Constructor Summary\n\n|---|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | [Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder#Builder())() Constructs an instance of the [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder). |\n\n### Public Method Summary\n\n|-------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Session](/android/reference/com/google/android/gms/fitness/data/Session) | [build](/android/reference/com/google/android/gms/fitness/data/Session.Builder#build())() Finishes building and returns the session. |\n| [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder) | [setActiveTime](/android/reference/com/google/android/gms/fitness/data/Session.Builder#setActiveTime(long,%20java.util.concurrent.TimeUnit))(long time, [TimeUnit](//developer.android.com/reference/java/util/concurrent/TimeUnit.html) timeUnit) Sets the active session period duration. |\n| [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder) | [setActivity](/android/reference/com/google/android/gms/fitness/data/Session.Builder#setActivity(java.lang.String))([String](//developer.android.com/reference/java/lang/String.html) activity) Sets the activity associated with this session. |\n| [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder) | [setDescription](/android/reference/com/google/android/gms/fitness/data/Session.Builder#setDescription(java.lang.String))([String](//developer.android.com/reference/java/lang/String.html) description) Sets a description for this session. |\n| [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder) | [setEndTime](/android/reference/com/google/android/gms/fitness/data/Session.Builder#setEndTime(long,%20java.util.concurrent.TimeUnit))(long time, [TimeUnit](//developer.android.com/reference/java/util/concurrent/TimeUnit.html) timeUnit) Sets the end time of the session. |\n| [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder) | [setIdentifier](/android/reference/com/google/android/gms/fitness/data/Session.Builder#setIdentifier(java.lang.String))([String](//developer.android.com/reference/java/lang/String.html) identifier) Sets the identifier for this session. |\n| [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder) | [setName](/android/reference/com/google/android/gms/fitness/data/Session.Builder#setName(java.lang.String))([String](//developer.android.com/reference/java/lang/String.html) name) Sets the a human readable name of the session. |\n| [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder) | [setStartTime](/android/reference/com/google/android/gms/fitness/data/Session.Builder#setStartTime(long,%20java.util.concurrent.TimeUnit))(long time, [TimeUnit](//developer.android.com/reference/java/util/concurrent/TimeUnit.html) timeUnit) Sets the start time of the session. |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Constructors\n-------------------\n\n#### public **Builder** ()\n\nConstructs an instance of the [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder).\n\nPublic Methods\n--------------\n\n#### public [Session](/android/reference/com/google/android/gms/fitness/data/Session)\n**build** ()\n\nFinishes building and returns the session. Returned session will always have\nnon-empty non-null identifier. \n\n##### Throws\n\n| [IllegalStateException](//developer.android.com/reference/java/lang/IllegalStateException.html) | If the builder doesn't have enough state to create a valid request. |\n|-------------------------------------------------------------------------------------------------|---------------------------------------------------------------------|\n\n#### public [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder)\n**setActiveTime** (long time, [TimeUnit](//developer.android.com/reference/java/util/concurrent/TimeUnit.html) timeUnit)\n\nSets the active session period duration. \n\n#### public [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder)\n**setActivity** ([String](//developer.android.com/reference/java/lang/String.html) activity)\n\nSets the activity associated with this session. The specified activity value should\nbe one of the values in [FitnessActivities](/android/reference/com/google/android/gms/fitness/FitnessActivities).\nIf an unrecognized value is specified, or if not specified, the activity for the\nsession is set to [FitnessActivities.UNKNOWN](/android/reference/com/google/android/gms/fitness/FitnessActivities#UNKNOWN). \n\n#### public [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder)\n**setDescription** ([String](//developer.android.com/reference/java/lang/String.html) description)\n\nSets a description for this session. \n\n#### public [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder)\n**setEndTime** (long time, [TimeUnit](//developer.android.com/reference/java/util/concurrent/TimeUnit.html) timeUnit)\n\nSets the end time of the session. If end time is not specified, session is\nconsidered to be still ongoing. \n\n##### Parameters\n\n| time | An end time, in the given unit since epoch, inclusive. |\n| timeUnit | The unit of the timestamp. |\n|----------|--------------------------------------------------------|\n\n#### public [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder)\n**setIdentifier** ([String](//developer.android.com/reference/java/lang/String.html) identifier)\n\nSets the identifier for this session. Must be unique for the client application. \n\n#### public [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder)\n**setName** ([String](//developer.android.com/reference/java/lang/String.html) name)\n\nSets the a human readable name of the session. \n\n#### public [Session.Builder](/android/reference/com/google/android/gms/fitness/data/Session.Builder)\n**setStartTime** (long time, [TimeUnit](//developer.android.com/reference/java/util/concurrent/TimeUnit.html) timeUnit)\n\nSets the start time of the session. \n\n##### Parameters\n\n| time | A start time, in the given unit since epoch, inclusive. |\n| timeUnit | The unit of the timestamp. |\n|----------|---------------------------------------------------------|"]]