0

I got a error caused by user press a button too fast in a short time. The following is the error:

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 

How can i prevent the problem like that?

4
  • 1
    please explain it a bit more further. cudn't get you. Commented Jun 27, 2012 at 6:14
  • @ting fu sit : Disable the button on the first press/click - is that too difficult to work out? Commented Jun 27, 2012 at 6:17
  • stackoverflow.com/questions/4199191/… please look at this to see if the top answer can work for your app Commented Jun 27, 2012 at 6:17
  • If webservice call is there, then AsyncTask with ProgressDialog (Not cancellable) is the best solution Commented Jun 27, 2012 at 6:21

2 Answers 2

2

Are you calling a web service after the button is tapped ? There are several options:

1.Add a progress dialog that will disable anything in the background.If it is a web service this is the best solution.

2.Disable any UI element in the screen for the time period that you are performing any action.

3.Spawn a new thread or an async task.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use an Boolean Variable for prevanting to run your code on every button click as:

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; } 

3 Comments

quite pointless, because if doWork() does not return, onClick() does not get called again.
@lenik : any example when doWork() not return , if you are using return "xxxx" in doWork()?
his main problem is the onClick() handler which does not return in time, hence the keyDispatchingTimedOut error. the correct solution will be offloading work into another thread.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.