How can I remove a ValueEventListener that I am using in "doInBackground" from "onPostExecute" in an "asynchronous task" in java because I am creating an intent in "onPostExecute" and I need to make sure that the listener is removed before I go to another activity?
Asked
Active
Viewed 80 times
0

Frank van Puffelen
- 565,676
- 79
- 828
- 807

new user
- 61
- 1
- 4
-
To remove a listener from the Firebase Realtime Database, call the relevant [`removeEventListener` method](https://firebase.google.com/docs/reference/android/com/google/firebase/database/Query.html#removeEventListener(com.google.firebase.database.ValueEventListener)). Beyond that link it's hard to help without seeing the [minimal code that reproduces what you are asking about](http://stackoverflow.com/help/mcve). – Frank van Puffelen Apr 12 '19 at 04:03
-
Check **[this](https://stackoverflow.com/questions/48861350/should-i-actually-remove-the-valueeventlistener/48862873)** out. – Alex Mamo Apr 12 '19 at 08:45
1 Answers
0
is this you need?
ValueEventListener velOneTime;
DatabaseReference mRefChild;
if (velOneTime != null) mRefChild.removeEventListener(velOneTime);
use it either onStop or onDestory, depending on your logic.

hemen
- 1,460
- 2
- 16
- 35