我有一个游戏,我使用几个表来存储玩家的进度。这是一个相当长的游戏,所以我时不时会收到关于为什么我没有云保存选项的合法用户反馈?
因此,我确实使用 Google Play 游戏登录来取得成就,我想我可以简单地实现 Google Saved Games也很简单。
正如我所见,它使用一个简单的 byte[]
数组来从云端保存和加载游戏进度。(实际上是 Google Drive。)
我的问题是,如何创建一个 byte[]
数组来保存玩家已保存游戏实例的完整数据库?
我正在使用Sqlite数据库,例如:
private static DatabaseHelper mInstance = null;
private DatabaseHelper(Context context) {
super(context, "duels_rpg_db", null, 123);
this.ctx = context;
getWritableDatabase();
}
public static DatabaseHelper getInstance(Context ctx) {
if (mInstance == null) {
mInstance = new DatabaseHelper(ctx.getApplicationContext());
}
return mInstance;
}
等等,没什么特别的。
提前致谢,
最佳答案
如果你是using C it would be easy to serialize the entire database ,但在 Android 中我认为你必须 locate the database file ,使用 ByteArrayOutputStream 类将其转换为字节数组,将其存储在 Google Saved Games 中,然后在必要时将字节数组转换回文件。有关将文件转换为字节数组以及反之亦然的示例 see this link .
关于android - 从 SqliteDatabase 创建字节数组以使用 Google Saved Games 保存它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65037390/