Firebase离线缓存如何工作?

时间:2020-06-29 17:10:31

标签: android firebase

我想知道,如果我缓存来自firebase的所有数据,并且在关闭wifi之后,它是否能像以前一样工作。但是,如果我关闭wifi并重新启动电话,然后输入没有wifi的程序,它可以正常工作吗?

2 个答案:

答案 0 :(得分:1)

如果您使用房间或本地存储来保存数据,则可以使用

示例

val sharedPref = activity?.getPreferences(Context.MODE_PRIVATE) ?: return
with (sharedPref.edit()) {
    putInt(getString(R.string.saved_high_score_key), newHighScore)
    commit()
}

链接代码

https://developer.android.com/training/data-storage/shared-preferences

房间

依赖性{

  def room_version = "2.2.5"

  implementation "androidx.room:room-runtime:$room_version"
  annotationProcessor "androidx.room:room-compiler:$room_version" // For Kotlin use kapt instead of annotationProcessor

  // optional - Kotlin Extensions and Coroutines support for Room
  implementation "androidx.room:room-ktx:$room_version"

  // optional - RxJava support for Room
  implementation "androidx.room:room-rxjava2:$room_version"

  // optional - Guava support for Room, including Optional and ListenableFuture
  implementation "androidx.room:room-guava:$room_version"

  // Test helpers
  testImplementation "androidx.room:room-testing:$room_version"
}

https://developer.android.com/topic/libraries/architecture/room?gclid=EAIaIQobChMIhM-Qi8en6gIVCZ2zCh3PMQSNEAAYASAAEgIUP_D_BwE&gclsrc=aw.ds

您只需要保存json

答案 1 :(得分:0)

是的,您仍然可以查询数据,因为数据已保存在设备的存储器中。对于您来说,这应该很容易尝试。