I did a reasonable amount of research and can not find the answer I need.
What I DO know: When I attach a ValueEventListener to a database reference, I know I need to remove it later (finding that out the hard way now with some massive memory leakage.
What I DON'T know: Do I also need to detach all other listeners? (This is to include Firebase Database, Storage, and Auth, the three APIs I am using)
Example:
UploadTask uploadTask = ref.putFile(uploadFile);
uploadTask.addOnFailureListener(new OnFailureListener() {
//@Override code here
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TakeSnapshot>() {
//@Override code here
}).addOnProgressListner(new OnProgressListner<UploadTask.TakeSnapshot>() {
//@Override code here
};
I think that's enough to show you the point of what I mean. This is how my actual code is currently structured.
Questions:
- Do I need to remove all of those listeners just in case the activity is terminated (system decision, phone dies, whatever) before that callback happens?
- Can I bundle them up somehow and terminate them all three at once because I have like 30 of these in my code and really don't feel like restructuring all of it in order to assign all these listeners to variables JUST so I can pass them into the "removeBlahBlahBlahListener(listenerVariable)" over and over.
- Slightly off topic, but, I am too lazy to move all my code from onCreate to onStart... is is bad practice for me to remove all these listeners, finish things up, call finish() (or whatever it is that kills off an activity, although I guess this is not guaranteed) and just recreate the activity from scratch? It's a small simple app so the overhead of re-creating the activity is no biggie. Just curious what is "right".
I imagine this is just a result of poor planning and lack of knowledge (I only program for fun, not for a job unfortunately) so if I have to take the hard route I guess it's a learning experience, right?