android - How to destroy a fragment and then create a new? -
i have fragment plays videos, start application , goes perfectly, when press button , select video file play, view not play video.
videoactivity
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_video); a=this; th = thread.currentthread(); // obter url vÍdeo bundle extras = getintent().getextras(); if (extras != null) _videourl = extras.getstring("caminho_arquivo"); if (savedinstancestate == null) { getfragmentmanager().begintransaction() .add(r.id.container, new placeholderfragment()).commit(); } } public static class placeholderfragment extends fragment { static private final int buffer_size = 700;// mb static private final int num_files = 20;// count files in cache dir public placeholderfragment() {} @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_video, container, false); frame1 = rootview.findviewbyid(r.id.frame1); textureview = (videoplayer) rootview.findviewbyid(r.id.textureview1); textprogress = (textview) rootview.findviewbyid(r.id.textview1); textureview.setvideopath(_videourl); textureview.setmediacontroller(new mediac(a, frame1)); textureview.setseeklistener(new videoplayer.seeklistener() { @override public void onseek(int msec) { //if (proxy != null) //{ //proxy.seek = true; //} // more speed seeking } @override public void onseekcomplete(mediaplayer mp) {} }); textureview .setonpreparedlistener(new mediaplayer.onpreparedlistener() { @override public void onprepared(final mediaplayer mp) { textureview.start(); } }); return rootview; }
as far can see in code, creating fragment if savedinstancestate
null. so, if activity not destroyed, use same fragment.
instead, remove part oncreate()
, create fragment in every time navigate videoactivity.
Comments
Post a Comment