kandi X-RAY | BodyET Summary
kandi X-RAY | BodyET Summary
BodyET
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of BodyET
BodyET Key Features
BodyET Examples and Code Snippets
Community Discussions
Trending Discussions on BodyET
QUESTION
Here is my situation.
In this screen, I click the comments button.
The Comment activity opens and I type what I want.
The comment is added successfully in firebase and it takes me back in detail activity.
So far everything is great! Now let's add another comment. Now you see I get duplicate comments.
I hope you see that too. Now in the DetailActivity I have a method called queryFirebaseDb()
and that method is called inside both onCreate()
and onResume()
methods. If I don't use the onResume() method the data will not be display after clicking the back button from the CommentActivity. You see where I am going now right? The question is how to avoid duplicate data after coming back from CommentActivity. Here is my code.
ANSWER
Answered 2018-May-27 at 14:29Some stuff I thought you would know when doing Android:
Basically, in android, you need to understand how the life cycle works. So, when you call queryFirebaseDb()
from onCreate
and from onResume
, your app is doing two queries at the same time when activity starts initially.
Lifecycle is like this OnCreate -> onResume
. So, it makes sense that when activity starts, query gets executed once on onCreate
than on onResume
based on your logic.
Answer is here
I noticed that you are using ArrayList commentArrayList;
, which is an ArrayList
structure, which lets you have duplicate data. And, if you look into the behavior of Firebase
and how your query is structured, it is like this,
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install BodyET
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page