无论如何,当互联网连接不可用时,是否可以保存 firebase 实时数据库数据
Is there anyway to save firebase realtime db data when internet connection is not available
我正在用 kotlin 制作考勤 android 应用程序。在此应用程序中,学生列表可通过 sqlite db 离线使用。
为了节省出勤率,我正在使用 Firebase 实时数据库。
但是,我想制作也可以在离线模式下工作的应用程序。并在互联网可用时上传考勤,即使在重新启动应用程序后。
恕我直言,我看不出实施这种机制有什么好处,因为实时数据库有自己的离线持久化机制。根据 official documentation:
Firebase apps automatically handle temporary network interruptions. Cached data is available while offline and Firebase resends any writes when network connectivity is restored.
When you enable disk persistence, your app writes the data locally to the device so your app can maintain its state while offline, even if the user or operating system restarts the app.
因此,在离线状态下,您可以继续使用该应用程序。在 Android 中,这可以简单地使用:
Firebase.database.setPersistenceEnabled(true)
我正在用 kotlin 制作考勤 android 应用程序。在此应用程序中,学生列表可通过 sqlite db 离线使用。
为了节省出勤率,我正在使用 Firebase 实时数据库。
但是,我想制作也可以在离线模式下工作的应用程序。并在互联网可用时上传考勤,即使在重新启动应用程序后。
恕我直言,我看不出实施这种机制有什么好处,因为实时数据库有自己的离线持久化机制。根据 official documentation:
Firebase apps automatically handle temporary network interruptions. Cached data is available while offline and Firebase resends any writes when network connectivity is restored.
When you enable disk persistence, your app writes the data locally to the device so your app can maintain its state while offline, even if the user or operating system restarts the app.
因此,在离线状态下,您可以继续使用该应用程序。在 Android 中,这可以简单地使用:
Firebase.database.setPersistenceEnabled(true)