I have Class A with an instance variable ImageView. Currently I use setTag() to get from the ImageView back to the instance of Class A. Could that present circular loop? I also heard of mention of weak references. What is the best way to get at the parent Class A of the ImageView?
My usage scenario is I am dragging the ImageView around the screen and I need to access class A for information about the ImageView being dragged.
I believe that Dalvik VM doesn’t have problem with detecting circular references.
Here’s Q/A that discusses this: Circular References in Java
I’d use setTag to hold ref to related object. Also, using setTag/getTag on View is standard and recommended approach to achieve various optimizations on Android, even found in Android samples.
Some references:
http://www.vogella.de/articles/AndroidListView/article.html#ownadapter_viewHolder
Android Custom Listview
If Android’s GC would have problem to detect such dependencies, Android would not work as it works.
Go ahead and use View.setTag if it suits your purpose.