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