为什么虽然允许备份应用程序,但重新安装应用程序有时会清除 SP?

Why re-installing an application sometimes clears SP although app backup is allowed?

我注意到重新安装我的应用程序(在调试模式下一次又一次地构建它)有时会清除我的 SP,有时不会。 我认为在 Manifest.xml 文件的应用程序选项卡中添加 android:allowBackup="true" 可能会在我重新构建应用程序时随时恢复它。

<application 
android:allowBackup="true" 
.
.
.
>
  1. 是否一遍又一遍地构建应用程序实际上是将其卸载然后重新安装?如果它确实如此工作,那么它在发布模式下是否也一样工作?
  2. android:allowBackup="true"实际上是做什么的?我认为它会在 phone 上创建一个永久文件,指向需要备份的重要数据。
  3. 通过Google Play 更新应用程序时,实际过程是怎样的?该应用程序是否已卸载然后重新安装?还是只是更新必要的代码?对内存有什么影响?
  4. 我的共享首选项实际上被删除的真正原因是什么?

当涉及到共享首选项之类的东西时,它们通常应该在调试会话之间保留(假设您没有手动从 emulator/device 中删除应用程序)。

检查 Visual Studio 的设置以确保它正在 尝试 保留 data/cache 目录:

  • Preserve data/cache between application deploys

阅读有关 "Fast Deployment" 的部分,了解 Xamarin 如何处理调试构建更新:

在开发过程中 "Auto Backup" (android:allowBackup="true") 几乎无关紧要,请参阅下面的条件,它会备份到您的 Google Drive 帐户。

Backups occur automatically when all of the following conditions are met:

  • The user has enabled backup on the device.
  • At least 24 hours have elapsed since the last backup.
  • The device is idle.
  • The device is connected to a Wi-Fi network (if the device user hasn't opted in to mobile-data backups).

Android (Back up user data with Auto Backup) 文档对此进行了更详细的介绍。