android - Youtube Leaked Service Connection when setRaetainInstance(true) -
i have problems following error:
04-26 11:41:58.662: e/activitythread(10933): activity myactivity has leaked serviceconnection com.google.android.youtube.player.internal.r$e@2cf388d bound here
i have fragment , set following in oncreate:
/** * */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); this.setretaininstance(true); }
i set because have list of youtubevideos thumbnails , dont want these thumbnails reloaded everytime user rotates screen. thats unnecessary traffic.
the following adapter listview:
public class youtubelistadapter extends baseadapter { private list<tutorialentry> entries = null; private list<view> entryviews = null; private map<youtubethumbnailview, youtubethumbnailloader> thumbnailviewtoloadermap = null; private layoutinflater inflater = null; private tutorialthumbnaillistener thumbnaillistener = null; private boolean labelsvisible = false;; public youtubelistadapter(context context, list<tutorialentry> entries) { this.entries = entries; this.entryviews = new arraylist<view>(); this.thumbnailviewtoloadermap = new hashmap<youtubethumbnailview, youtubethumbnailloader>(); this.inflater = layoutinflater.from(context); this.thumbnaillistener = new tutorialthumbnaillistener(this.thumbnailviewtoloadermap); this.labelsvisible = true; } @override public int getcount() { return this.entries.size(); } @override public tutorialentry getitem(int position) { return entries.get(position); } @override public long getitemid(int position) { return position; } @override public view getview(int position, view convertview, viewgroup parent) { tutorialentry entry = entries.get(position); viewholder holder = null; if (convertview == null) { convertview = this.inflater.inflate(r.layout.fragment_tutorials_row, parent, false); holder = new viewholder(); holder.thumbnail = (youtubethumbnailview) convertview.findviewbyid(r.id.tutorials_row_thumbnail); holder.thumbnail.settag(entry.getvideoid()); holder.thumbnail.initialize(globals.google_api_key, this.thumbnaillistener); holder.textviewtitle = (textview) convertview.findviewbyid(r.id.tutorials_row_title); convertview.settag(holder); } else { holder = (viewholder) convertview.gettag(); youtubethumbnailloader loader = this.thumbnailviewtoloadermap.get(holder.thumbnail); if (loader == null) { holder.thumbnail.settag(entry.getvideoid()); } else { holder.thumbnail.setimageresource(r.drawable.youtube_loading_thumbnail); loader.setvideo(entry.getvideoid()); } } holder.textviewtitle.settext(entry.gettitle()); holder.textviewtitle.setvisibility(labelsvisible ? view.visible : view.gone); return convertview; } public void releaseloaders() { (youtubethumbnailloader loader : this.thumbnailviewtoloadermap.values()) { loader.release(); } } public void setlabelvisibility(boolean labelsvisible) { this.labelsvisible = labelsvisible; (view view : this.entryviews) { view.findviewbyid(r.id.tutorials_row_title).setvisibility(labelsvisible ? view.visible : view.gone); } } private static class viewholder { private youtubethumbnailview thumbnail = null; private textview textviewtitle = null; } }
the problem occurs in line:
holder.thumbnail.initialize(globals.google_api_key, this.thumbnaillistener);
can me understand happening there , how can solve this?
this exception comes not releasing loaders. can tell, never call releaseloaders()
method, since loaders sort of sitting there activity becomes torn down. way android designed, should release these loaders, else you'll memory leaks.
personally, put loader releases in onstop()
method , works exquisitely.
@override public void onstop() { super.onstop(); (youtubethumbnailloader loader : thumbnailviewtoloadermap.values()) { loader.release(); } }
Comments
Post a Comment