Issue
i had a problem with my application where sometimes it successfully delete a file and most of the time it is failed to delete it. At first i thought it was my application that had the problem. here is how it looked in my application, the button that i clicked is the delete button :
But, then i tried to delete the data directly from firebase realtime database but the child node is refused to be deleted. here is how it looked :
I tried to check my delete function. But, i dont think there is anything wrong with it. here is my delete function :
private fun removeData(id : String){
val dataRef = ref.child(preferences.getValue("username").toString()).child("FoodList").child(id)
val Image = StorageRef.child(preferences.getValue("username").toString()).child("food_pics").child(id)
dataRef.removeValue()
Image.delete()
}
I tried to look for this problem everywhere but i still got no answer. I hope anyone in here could help me, thanks
Solution
Turnout this problem is caused by a ValueEventListener in my program which is used to set a value to my realtime database.This create a value to be set continuously by my program. Which then, create such behavior in the realtime database. Before, it was like this :
dataRef.addValueEventListener(object : ValueEventListener{
override fun onDataChange(snapshot: DataSnapshot) {
Log.w("PicUrl data",PicUrl)
dataRef.child("name").setValue(food_name)
dataRef.child("avail").setValue(availability)
dataRef.child("price").setValue(food_price.toInt())
dataRef.child("id").setValue(id)
}
override fun onCancelled(error: DatabaseError) {
Toast.makeText(applicationContext,"Error",Toast.LENGTH_SHORT)
}
})
now i just simply set the value without ValueEventListener :
dataRef.child("name").setValue(food_name)
dataRef.child("avail").setValue(availability)
dataRef.child("price").setValue(food_price.toInt())
dataRef.child("id").setValue(id)
Answered By - MadsterMIZE
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.