I am stumped on this. I can’t seem to figure out how properly create new listeners in android to avoid memory leaks. Would I use a static inner class with a SoftReference to the outer class (since I need to access the outer class variables)? Or should i do something like this:
setScrollListener(new ScrollListner {
//methods here.
});
A memory leak should only occur if the Scrolllistener is referenced from something outside your activity.
If you use the scrolllistener as it is in you code the listener will keep a reference to you Activity because it is an anonymous class. But the only reference to your listener will be from the views that are references from this activity. Once the activity is finished the garbage collector can clean up the whole memory at once.