【发布时间】:2021-05-09 11:46:24
【问题描述】:
我们有一个简单的问答游戏,目前正在使用 Room 数据库来存储包括用户进度在内的所有数据。我们现在想要集成 Google play 游戏服务来将进度存储在云端,以便用户在更换设备或重新安装游戏时可以了解他们的进度。
目前我们在 xml 文件中包含游戏类别和关卡详细信息,然后在第一次运行应用程序时对其进行解析并将数据存储在 Room 数据库中。
我们查看了游戏服务的文档,知道有这种方法可以保存游戏。
private Task<SnapshotMetadata> writeSnapshot(Snapshot snapshot,
byte[] data, Bitmap coverImage, String desc) {
// Set the data payload for the snapshot
snapshot.getSnapshotContents().writeBytes(data);
// Create the change operation
SnapshotMetadataChange metadataChange = new SnapshotMetadataChange.Builder()
.setCoverImage(coverImage)
.setDescription(desc)
.build();
SnapshotsClient snapshotsClient =
Games.getSnapshotsClient(this, GoogleSignIn.getLastSignedInAccount(this));
// Commit the operation
return snapshotsClient.commitAndClose(snapshot, metadataChange);
}
但问题是,这种方法需要字节来写入快照,并且我们在 Room 数据库中有数据,我们可以从 Room db 传递数据还是必须更改本地数据库?
【问题讨论】:
标签: android android-room google-play-games android-database