android - Commonsware camera preview demo: no preview after device on/off -


i see bug: when camera in preview mode, , user presses on/off, camera preview stops , not start.

an obvious suggestion see other people do; have consulted https://github.com/commonsguy/cw-advandroid/tree/master/camera/preview/ , see demo has same bug (android 4.0.3).

a direct link java source: https://github.com/commonsguy/cw-advandroid/blob/master/camera/preview/src/com/commonsware/android/camera/previewdemo.java

question: how can 1 fix bug? preview mode must working after device on/off.

upd: bug not show if first change activity , press on/off on activity.

upd2: after on/off, startpreview() invoked, see message system:

d/@@    (13428): startpreview() cameraconfigured=true camera=android.hardware.camera@412f66f0 e/camhw ( 2135): preview window null! 

which means bad happen in depths of system (although message may device-specific).

udp3: after on/off, no method surfacecallback invoked. maybe makes difference.

upd4: [seen not @ camera demo] if switch different application (by long-pressing home , choosing list) , switch back, camera works again.

it not solution, workaround: invoke setcontentview() in onresume().

it can either

protected void onresume() {     super.onresume();     setcontentview(r.layout.xxx);     // ... } 

or

private view cachedcontentview; protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     cachedcontentview = docreatecontentview(getlayoutinflater());     // ... } protected void onresume() {     super.onresume();     setcontentview(cachedcontentview);     // ... } 

both of them work.

i still have no idea causes problem , the difference between original example , library.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -