Android ANR keyDispatchingTimedOut Error while continuous tapping on screen

UI线程,主线程阻塞(blocking).新启一个线程,并由Handler来执行.

 

[java]  view plain copy print ?
  1. @Override  
  2.     public void onScroll(AbsListView view, final int firstVisibleItem,  
  3.             final int visibleItemCount, final int totalItemCount) {  
  4.           
  5.         Thread songsList = new Thread(){  
  6.             @Override  
  7.             public void run(){  
  8.                 firstItem = firstVisibleItem;  
  9.                 visibleCout = visibleItemCount;  
  10.                 totalCount = totalItemCount;  
  11.                 Message message = new Message();  
  12.                 message.what = 2;  
  13.                 handler.sendMessage(message);  
  14.             }  
  15.         };  
  16.         songsList.start();  
  17.           
  18.     }  
  19.   
  20. Handler handler = new Handler() {  
  21.         @Override  
  22.         public void handleMessage(Message msg) {  
  23.             super.handleMessage(msg);  
  24.             switch (msg.what) {  
  25. case 2:  
  26.                 if ((firstItem + visibleCout == totalCount)  
  27.                         && (totalCount != 0)) {  
  28.                     if (refreshAble) {  
  29.                         refreshAble = false;  
  30.                         loading.setVisibility(View.VISIBLE);  
  31.                         /** 
  32.                          * 获取下一页数据 
  33.                          */  
  34.                         getData(++pageNo);  
  35.                     }  
  36.                 }  
  37.                 break;  
  38.             default:  
  39.                 break;  
  40.             }  
  41.         }  
  42.     };  



 

REFRENCES:http://stackoverflow.com/questions/4529770/android-anr-keydispatchingtimedout-error-while-continuous-tapping-on-screen

http://developer.android.com/resources/articles/painless-threading.html

你可能感兴趣的:(Dispatch)