How can I fix the following Error inside my activity?
Caused by: com.google.firebase.database.DatabaseException: Calls to setPersistenceEnabled() must be made before any other usage of FirebaseDatabase instance.
I set setPersistenceEnabled() like that in my activity:
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.ViewThat_add -> {
val intent = Intent(this, Add::class.java)
startActivity(intent)
}
R.id.ViewThat_delete -> {
delete()
}
R.id.ViewThat_Download -> {
enablePersistence()
download()
}
}
return super.onOptionsItemSelected(item)
}
private fun enablePersistence() {
FirebaseDatabase.getInstance().setPersistenceEnabled(true)
}
Inside the documentation it was made very similar to this, I don't really know how to fix this error.