android / health-samples

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

app crash after startExercise or endExercise

haozes opened this issue · comments

commented

I got some error logs from my user's devices.

crash1:

androidx.health.services.client.impl.IExerciseApiService$Stub$Proxy.startExercise
android.os.DeadObjectException

android.os.BinderProxy.transactNative BinderProxy.java
android.os.BinderProxy.transact BinderProxy.java:567
androidx.health.services.client.impl.IExerciseApiService$Stub$Proxy.startExercise
androidx.health.services.client.impl.ServiceBackedExerciseClient.startExerciseAsync$lambda$3
androidx.health.services.client.impl.ServiceBackedExerciseClient.k
androidx.health.services.client.impl.c.execute
androidx.health.services.client.impl.ipc.Client$3.execute
androidx.health.services.client.impl.ipc.internal.ServiceConnection.execute
androidx.health.services.client.impl.ipc.internal.ServiceConnection.enqueue
androidx.health.services.client.impl.ipc.internal.ConnectionManager.handleMessage
android.os.Handler.dispatchMessage Handler.java:102
android.os.Looper.loop Looper.java:246
android.os.HandlerThread.run HandlerThread.java:67

crash2:

Package: com.xxx.myapp
Version Code: 200105
Version Name: 1.69
Android: 11
Android Build: RWS3.220419.001
Manufacturer: samsung
Model: SM-R865F
CrashReporter Key: 4b532657-4679-4bcd-9186-0015c7f59180
Start Date: 2023-05-04T09:07:17.817Z
Date: 2023-05-04T09:29:27.241Z

androidx.health.services.client.HealthServicesException: Failed to end exercise with error: com.xxx.myapp doesn't have an active exercise.
  at androidx.health.services.client.impl.internal.StatusCallback.onFailure(Unknown Source:23)
  at androidx.health.services.client.impl.internal.IStatusCallback$Stub.onTransact(Unknown Source:32)
  at android.os.Binder.execTransactInternal(Binder.java:1159)
  at android.os.Binder.execTransact(Binder.java:1123)

I can't reproduce these issues from my device, If I surround startExercise __ endExerciseAsync__ with a try catch, will that prevent the crash happening?

before:

 exerciseClient.startExerciseAsync(config).await()
....
exerciseClient.endExerciseAsync().await()

change to:

   try {
            exerciseClient.startExercise(config)
        } catch (e: Exception) {
            Log.e(TAG, "Start exercise failed - ${e.message}")
        }

    ....
        try {
            exerciseClient.endExercise()
            exerciseClient.clearUpdateCallback(this)
        } catch (e: Exception) {
            Log.e(TAG, "End exercise failed - ${e.message}")
        }

I don't know why it crashes, and those methods don't need to catch exceptions.
In addition, I'm using androidx.health:health-services-client:1.0.0-beta02

Hey @haozes! Are you calling the exerciseClient.startExercise and exerciseClient.endExercise functions from within a foreground service? This will help ensure correct operation for the entire workout.

commented

Thanks for reply @breanatate
Nope, I am calling exerciseClient.startExercise and exerciseClient.endExercise from UI thread. There is a foreground service for collecting sensor data and calculating.

Do I need to call exerciseClient functions in the foreground service?

Hi @haozes Yes, that would help. In the event that another process starts on the watch, preparing and starting the exercise within a foreground service should ensure that the exercise isn't ended prematurely.

Hi @haozes, checking in. Did calling the functions from inside the foreground service fix the issue?

Hi @haozes, checking in. Did calling the functions from inside the foreground service fix the issue?

thanks for help. It's fixed. but don't know why it must be used in foreground service. Is there any particular reason?
Thanks again.