0

由于用户在短时间内按下按钮太快而导致错误。以下是错误:

06-27 12:46:51.500: ERROR/ActivityManager(115): ANR in test.test.test (test.test.test/.testActivity)
06-27 12:46:51.500: ERROR/ActivityManager(115): Reason: keyDispatchingTimedOut
06-27 12:46:51.500: ERROR/ActivityManager(115): Load: 3.94 / 2.98 / 2.63
06-27 12:46:51.500: ERROR/ActivityManager(115): CPU usage from 5863ms to 0ms ago:
06-27 12:46:51.500: ERROR/ActivityManager(115):   5.6% 36/nandd: 0% user + 5.6% kernel
06-27 12:46:51.500: ERROR/ActivityManager(115):   1.7% 3/ksoftirqd/0: 0% user + 1.7% kernel
06-27 12:46:51.500: ERROR/ActivityManager(115):   1.5% 89/mediaserver: 1.5% user + 0% kernel / faults: 14 minor
06-27 12:46:51.500: ERROR/ActivityManager(115):   1% 5780/com.inno.wordcard: 1% user + 0% kernel / faults: 34 minor
06-27 12:46:51.500: ERROR/ActivityManager(115):   0.8% 115/system_server: 0.3% user + 0.5% kernel / faults: 8 minor
06-27 12:46:51.500: ERROR/ActivityManager(115):   0% 4933/kworker/0:0: 0% user + 0% kernel
06-27 12:46:51.500: ERROR/ActivityManager(115):   0.1% 176/com.android.systemui: 0.1% user + 0% kernel
06-27 12:46:51.500: ERROR/ActivityManager(115):   0.1% 1440/logcat: 0% user + 0.1% kernel
06-27 12:46:51.500: ERROR/ActivityManager(115): 93% TOTAL: 2.9% user + 9% kernel + 81% iowait
06-27 12:46:51.500: ERROR/ActivityManager(115): CPU usage from 217ms to 736ms later:
06-27 12:46:51.500: ERROR/ActivityManager(115):   7.6% 36/nandd: 0% user + 7.6% kernel
06-27 12:46:51.500: ERROR/ActivityManager(115):   3.8% 115/system_server: 0% user + 3.8% kernel
06-27 12:46:51.500: ERROR/ActivityManager(115):     1.9% 116/HeapWorker: 0% user + 1.9% kernel
06-27 12:46:51.500: ERROR/ActivityManager(115):     1.9% 149/InputDispatcher: 0% user + 1.9% kernel
06-27 12:46:51.500: ERROR/ActivityManager(115): 100% TOTAL: 0% user + 11% kernel + 88% iowait

我怎样才能防止这样的问题?

4

2 回答 2

2

点击按钮后您是否正在调用网络服务?有几种选择:

1.添加一个进度对话框,在后台禁用任何东西。如果它是一个网络服务,这是最好的解决方案。

2.在您执行任何操作的时间段内禁用屏幕中的任何 UI 元素。

3. 产生一个新线程或一个异步任务。

于 2012-06-27T06:17:35.660 回答
0

您可以使用布尔变量来防止在每次单击按钮时运行您的代码:

boolean isClicked=true;
Button btn = (Button) findViewById(YourId);
btn.setonClickListener(listener);
public onClickListener listener = new View.OnclickListener{
      onclick(View v){
      if(isClicked==true)
      {
        isClicked=false;
        doWork();
        //DO YOUR WORK HERE...
      }
      else
      {
        // DO NOTHING...
      }
      }
}
 public void doWork(){
      /// YOUR CODE HERE...

         //USE AsyncTask ,Hanlder,handlerThread, or Thread for performing long running         task in background on button click
        isClicked=true;


     }
于 2012-06-27T06:28:21.147 回答