Android ANR keyDispatchingTimedOut Error while continuous tapping on screen

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

@Override
	public void onScroll(AbsListView view, final int firstVisibleItem,
			final int visibleItemCount, final int totalItemCount) {
		
		Thread songsList = new Thread(){
			@Override
			public void run(){
				firstItem = firstVisibleItem;
				visibleCout = visibleItemCount;
				totalCount = totalItemCount;
				Message message = new Message();
				message.what = 2;
				handler.sendMessage(message);
			}
		};
		songsList.start();
		
	}

Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			switch (msg.what) {
case 2:
				if ((firstItem + visibleCout == totalCount)
						&& (totalCount != 0)) {
					if (refreshAble) {
						refreshAble = false;
						loading.setVisibility(View.VISIBLE);
						/**
						 * 获取下一页数据
						 */
						getData(++pageNo);
					}
				}
				break;
			default:
				break;
			}
		}
	};


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

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

posted @ 2011-12-28 22:04  Atlas's blog  阅读(146)  评论(0编辑  收藏  举报