Fix turn check worker exception (#6867)

AndroidFileHandle uses Gdx.files internally
This commit is contained in:
Timo T 2022-05-19 12:43:28 +02:00 committed by GitHub
parent 85ba9c2624
commit 07593d7034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,6 +16,7 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationCompat.DEFAULT_VIBRATE
import androidx.core.app.NotificationManagerCompat
import androidx.work.*
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.backends.android.AndroidApplication
import com.badlogic.gdx.backends.android.DefaultAndroidFiles
import com.unciv.logic.GameInfo
@ -256,6 +257,8 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame
// We can't use Gdx.files since that is only initialized within a com.badlogic.gdx.backends.android.AndroidApplication.
// Worker instances may be stopped & recreated by the Android WorkManager, so no AndroidApplication and thus no Gdx.files available
val files = DefaultAndroidFiles(applicationContext.assets, ContextWrapper(applicationContext), false)
// GDX's AndroidFileHandle uses Gdx.files internally, so we need to set that to our new instance
Gdx.files = files
gameSaver.init(files, null)
}
@ -402,4 +405,4 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame
notify(NOTIFICATION_ID_INFO, notification.build())
}
}
}
}