I have gone through the article http://developer.android.com/resources/articles/avoiding-memory-leaks.html . In this article it is suggested to use static inner class with Weak Reference .
public class GalleryVideo extends Activity {
private int AUDIO_NO = 1;
...........................
................
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gallery = (Gallery) findViewById(R.id.examplegallery);
gallery.setAdapter(new AddImgAdp(this));
}
static public class AddImgAdp extends BaseAdapter {
private int GalItemBg;
private Context cont;
private WeakReference<GalleryVideo> mGalleryVideo;
public AddImgAdp(Context c) {
mGalleryVideo = new WeakReference<GalleryVideo>(c);
TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
typArray.recycle();
}
public long getItemId(int position) {
final GalleryVideo galleryVideo = mGalleryVideo.get();
if(galleryVideo == null){
if(galleryVideo.AUDIO_NO==4){
..................
...............
}
}
}
}
}
Is it the correct way to inner class with weak ref.? Is the above code memory leak-safe?