Debugging Event code
If I wish to debug some code for a UI event, e.g.
public boolean onTouchEvent(MotionEvent me)
{
// code to be debugged
}
... and I hold onto this thread (UI):
After 5 seconds I will get this warning: Key dispatching timed out sending to com.hos/com.hos.MyActivity ... null to Window ...
After 20 seconds I will get: Key dispatching timed out sending to com.hos/com.hos.MyActivity ... null to Window ... Continuing to wait for key to be dispatched
After 35 seconds I will get: Key dispatching timed out sending to com.hos/com.hos.MyActivity ... null to Window ... timed out expired proc开发者_开发问答ess next Key & find new target
At this point, not only is my application frozen but so is the phone. Quite often I need to wait for the ANR and sometimes hard restart the phone.
Is there a way to debug this code for more than 35 seconds without freezing the app / phone?
If your processing may take more than milliseconds to process you may want to consider launching the processing in another thread which has access to a handler in the main thread.
Once you are done processing, you can then pass a message over to your handler which will then execute on the UI thread. This will help prevent those errors from coming up as well as make debugging your code easier.
If you are looking for an automated UI testing framework, perhaps you could look into integrating Robotium into your project.
精彩评论