0
我写的一个按钮,单击该按钮时,一个应用程序,下面的方法将被调用:如何处理android输入系统知道输入事件不会导致anr?
public void click(View view) {
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
所以,很显然,这会之后的下一个输入事件来引起ANR。我认为这个处理输入事件的click方法不会导致InputEventReceiver类中的finishInputEvent方法被调用,但是我错了,finishInputEvent仍然调用click方法是否返回。在InputEventReceiver类finishInputEvent方法是这样的:
public final void finishInputEvent(InputEvent event, boolean handled) {
if (event == null) {
throw new IllegalArgumentException("event must not be null");
}
if (mReceiverPtr == 0) {
Log.w(TAG, "Attempted to finish an input event but the input event "
+ "receiver has already been disposed.");
} else {
int index = mSeqMap.indexOfKey(event.getSequenceNumber());
if (index < 0) {
Log.w(TAG, "Attempted to finish an input event that is not in progress.");
} else {
int seq = mSeqMap.valueAt(index);
mSeqMap.removeAt(index);
nativeFinishInputEvent(mReceiverPtr, seq, handled);
}
}
event.recycleIfNeededAfterDispatch();
}
我想nativeFinishInputEvent将在输入系统队列中删除一个项目,以便ANR不会被引起的,但现在nativeFinishInputEvent仍然可以调用,为什么会ANR仍然引起?输入系统如何识别输入事件没有处理?
我当然知道,我只是想知道输入系统如何知道输入事件没有处理,而finishInputEvent仍然被调用。 – cong
你怎么知道这叫做? – Clyde
我使用演示调试了android源代码。 – cong