I am developing an Android Wear Tile and occasionally my app crashes with this stack trace.
2022-06-22 15:19:24.753 24101-24101/myapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: myapp, PID: 24101
java.util.concurrent.CancellationException
at kotlinx.coroutines.guava.JobListenableFuture.getInternal(ListenableFuture.kt:438)
at kotlinx.coroutines.guava.JobListenableFuture.get(ListenableFuture.kt:428)
at androidx.wear.tiles.TileService$TileProviderWrapper.lambda$onTileRequest$0(TileService.java:234)
at androidx.wear.tiles.TileService$TileProviderWrapper$$ExternalSyntheticLambda7.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:7690)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)
Caused by: kotlinx.coroutines.JobCancellationException: Job was cancelled; job=JobImpl{Cancelled}@d298571
I think this is occurring when my tile is refreshing. My tile is getting data from a REST API using Retrofit. The code looks something like this:
class WeatherTileService : TileService() {
private val serviceScope = CoroutineScope(Dispatchers.IO)
override fun onTileRequest(requestParams: TileRequest) = serviceScope.future {
Log.d("Tile", "Refreshing weather data")
val api = AmbientWeatherClient.getInstance()
val devices = api.listUsersDevices(APP_KEY, API_KEY)
...
Tile.Builder()
.setResourcesVersion(RESOURCES_VERSION)
.setFreshnessIntervalMillis(5 * 60 * 1000)
.setTimeline(
interface AmbientWeatherAPI {
@GET("devices")
suspend fun listUsersDevices(
@Query("applicationKey") applicationKey: String,
@Query("apiKey") apiKey: String
): List<Device>
}
I cannot figure out why this is happening. Any suggestions where to start digging?