Open smyffanon opened 10 months ago
Hello, it's difficult to say the cause without the logcat output but to accomplish the same I would use RxJava like this:
val retryCount = 100
val retryDelayMillis = 100
fetchExerciseDisposable = api.fetchExercise(deviceId, exerciseEntries.first())
.observeOn(AndroidSchedulers.mainThread())
.doFinally {
readIt = true
toggleButtonUp(fetchExerciseButton, R.string.read_exercise)
}
.retryWhen { errors ->
errors.zipWith(Observable.range(1, retryCount + 1)) { error, count ->
if (count <= retryCount) {
Log.w(TAG, "Retrying attempt $count after error: $error")
count
} else {
throw error
}
}.flatMap { count ->
Observable.timer(count * retryDelayMillis.toLong(), TimeUnit.MILLISECONDS)
}
}
.subscribe(
{ polarExerciseData: PolarExerciseData ->
// Handle successful data here
},
{ error: Throwable ->
// Handle error here
val errorDescription = "Failed to read exercise after $retryCount attempts. Reason: $error"
Log.w(TAG, errorDescription)
showSnackbar(errorDescription)
}
)
It can still need some tweaking but can't say extract reason as the log output is not konwn.
Platform your question concerns:
Device:
Description: I'm trying to work with this issue using the example app where reading an exercise will cause an error and I must keep retrying to get the exercise off - I've had occasions where the 10th time I tried (list, read, wait - list, read, wait - list, read, ....) the exercise came off, and sometimes I gave up after 30th or 40th time - this is usually my sleeping rr intervals, I try to get the exercise from waking around 4AM to leaving for work between 8 to 9.
I tried to modify the example app to keep retrying with no manual intervention until the exercise gets read, but I've not been a programmer for 10 years now, and never used Java / Kotlin.
My logic was
With my mods, the app just fails on my phone (no logcat messages) my code is below - I suspect I need to do stuff in the error handling that's way beyond my current Java / Kotlin. If I"m close, please comment - if it's way beyond my current Java,Kotlin, comment that too.
There's some extra code in there to name the output file so I can feed the output to some R routines, starts with the comment //sks
The very top part is mostly just copied from the get a list code, put inside a loop to ensure I get a valid list before trying to read.