android - How to restart camera efficiently in a fragment - Barcode Scanner -


i have 2 fragments in app , trying implement barcode scanner using zxingscanner library in 1 of them. implementation works fine. question related bad design.

when user scans valid code dialog box appears saying code valid. when dismiss dialog (by pressing ok) barcode scanner stops. address issue have following:

buttonconfirm.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view view) {                     popupview.dismiss();                     restartcamera();                 }             });  public void restartcamera(){     mscannerview.stopcamera(); //mscannerview = new zxingscannerview(getactivity());     mscannerview.startcamera(); } 

the problem approach when switch fragments camera still running behind. how can stop camera when switch first fragment , turn on , address issue. (i using viewpager implement fragments)

ok found solution. override setmenuvisibility method in camera fragment. if fragment visible call restartcamera() method otherwise stop camera.

@override public void setmenuvisibility(final boolean visible){     if (visible){         if (mscannerview != null) {             log.v("fragmentqr", "visible");             restartcamera();         }     }     else {         if (mscannerview != null){             mscannerview.stopcamera();             log.v("fragmentqr","invisible");         }     } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -