Android app freezes without ANR after moving code into runnable -


i'm implementing custom camera , use onpreviewframe() real-time fx. main effect (fx1) runnable , seems ok, dropping frames when needed.
second simpler fx (fx2) runs when fx1 off.
when fx2 running on main thread ok (it runs in 2msec) saw anr decided move second runnable, causing app freeze.

class fx2runnable implements runnable {     private byte[] data;     fx2runnable(byte[] _data) {         data = _data;     }      public void run() {         hview.fx2(data);          hview.post(new runnable() {             public void run() {                 hview.postinvalidate();                 //.invalidate(); caused anr!!             }         });         flag_fx2_processing = false;     } } 

here how call it

private previewcallback previewcallback=new previewcallback() {     public void onpreviewframe(byte[] data, camera cam) {         if(fx==1) {             // fx1             if(flag_fx1_processing) {                 //skip             } else {                 flag_fx1_processing = true;                 fx1thread = new thread(new fx1runnable());                 fx1thread.start();             }         } else {             // fx2             if(flag_fx2_processing) {                 //skip             } else {                 flag_fx2_processing = true;                 fx2thread = new thread(new fx2runnable(data));                 fx2thread.start();             }             /* old code , working fine                needed solve spare anr             //hview.fx2(data);             //hview.invalidate();             */         }     } } 

what doing wrong!?

by way, seems cannot freeze app on emulator, on device.

edit

tried runonuithread(runnable) instead of hview.post(runnable), seemed work had wait minutes see freezing app again! happens later happens again!

here's logcat

08-26 17:32:13.398: i/activitymanager(250): displayed it.jcsoft.abbracadabbra/.enhancedcamerapreviewactivity: +3s576ms 08-26 17:32:13.414: w/iinputconnectionwrapper(459): showstatusicon on inactive inputconnection 08-26 17:32:13.441: i/gps(9149): new network location: location[mprovider=network,mtime=1377531132668,mlatitude=44.1459721,mlongitude=12.4545174,mhasaltitude=false,maltitude=0.0,mhasspeed=false,mspeed=0.0,mhasbearing=false,mbearing=0.0,mhasaccuracy=true,maccuracy=43.887,mextras=bundle[mparcelleddata.datasize=212]] 08-26 17:32:15.441: d/dalvikvm(250): wait_for_concurrent_gc blocked 0ms 08-26 17:32:15.867: d/dalvikvm(250): gc_explicit freed 1300k, 23% free 16030k/20615k, paused 3ms+41ms, total 428ms 08-26 17:32:37.707: d/dalvikvm(250): gc_concurrent freed 1878k, 22% free 16105k/20615k, paused 4ms+110ms, total 888ms 08-26 17:32:37.855: d/dalvikvm(9149): null clazz in op_instance_of, single-stepping 08-26 17:32:49.375: d/dalvikvm(834): gc_concurrent freed 512k, 9% free 9179k/9991k, paused 336ms+218ms, total 4454ms 08-26 17:32:49.375: d/dalvikvm(834): wait_for_concurrent_gc blocked 1740ms 08-26 17:32:58.605: d/dalvikvm(250): gc_concurrent freed 1934k, 22% free 16098k/20615k, paused 5ms+32ms, total 284ms 08-26 17:33:00.070: d/sizeadaptivelayout(335): com.android.internal.widget.sizeadaptivelayout@422dcb90child view android.widget.framelayout@422edb18 measured out of bounds @ 95px clamped 96px 08-26 17:33:00.093: d/sizeadaptivelayout(335): com.android.internal.widget.sizeadaptivelayout@4231b860child view android.widget.framelayout@4231d180 measured out of bounds @ 95px clamped 96px 08-26 17:33:10.257: d/dalvikvm(9149): gc_concurrent freed 455k, 4% free 14709k/15303k, paused 3ms+4ms, total 78ms 08-26 17:33:20.082: d/dalvikvm(250): gc_concurrent freed 1933k, 22% free 16091k/20615k, paused 5ms+30ms, total 282ms 08-26 17:33:23.379: i/inputdispatcher(250): application not responding: window{425f23b0 it.jcsoft.abbracadabbra/it.jcsoft.abbracadabbra.enhancedcamerapreviewactivity paused=false}.  has been 5002.6ms since event, 5002.5ms since wait started.  reason: waiting because touched window has not finished processing input events delivered it. 08-26 17:33:23.379: i/windowmanager(250): input event dispatching timed out sending it.jcsoft.abbracadabbra/it.jcsoft.abbracadabbra.enhancedcamerapreviewactivity 08-26 17:33:28.437: i/inputdispatcher(250): dropped event because stale. 

please help!

you should use handler kind of operation.

have runnable post message once it's done it's operation , hview.postinvalidate(); method call.

there tons of guides how it.

some links include: http://developer.android.com/reference/android/os/handler.html

http://androidexample.com/thread_with_handlers_-_android_example/index.php?view=article_discription&aid=58&aaid=83

http://www.vogella.com/tutorials/androidbackgroundprocessing/article.html


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -