microg/GmsCore · error · IllegalStateException

Active time is not set

Error message

Active time is not set

What it means

State access guard in Session.getActiveTime: the optional active-time field was not set when the Session was created, so there is no value to return. hasActiveTime() is the documented pre-check and returns false exactly when this throws.

Source

Thrown at play-services-fitness/src/main/java/com/google/android/gms/fitness/data/Session.java:90

        this.startTimeMillis = startTimeMillis;
        this.endTimeMillis = endTimeMillis;
        this.name = name;
        this.identifier = identifier;
        this.description = description;
        this.activityType = activityType;
        this.application = application;
        this.activeTimeMillis = activeTimeMillis;
    }

    /**
     * Returns the active time period of the session.
     * <p>
     * Make sure to use {@link #hasActiveTime()} before using this method.
     *
     * @throws IllegalStateException {@link #hasActiveTime()} returns false.
     */
    public long getActiveTime(@NonNull TimeUnit timeUnit) {
        if (activeTimeMillis == null) throw new IllegalStateException("Active time is not set");
        return timeUnit.convert(activeTimeMillis, TimeUnit.MILLISECONDS);
    }

    /**
     * Returns the activity associated with this session, if set. Else returns {@link FitnessActivities#UNKNOWN}.
     */
    @NonNull
    public String getActivity() {
        return null; // TODO
    }

    /**
     * Returns the package name for the application responsible for adding the session. or {@code null} if unset/unknown. The {@link PackageManager} can be
     * used to query relevant data on the application, such as the name, icon, or logo.
     */
    @Nullable
    public String getAppPackageName() {
        if (application == null) return null;

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Call hasActiveTime() before getActiveTime() and branch on the result
  2. Fall back to endTime - startTime as an approximation when active time is unset
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at play-services-fitness/src/main/java/com/google/android/gms/fitness/data/Session.java:90 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06). Data as JSON: /api/errors/85492d0779df92f9. Report an issue: GitHub.