我有运行Visual Studio的Android模拟器和带有Android 8.1的物理设备诺基亚5。在这两个设备上,以下事件不断触发:
private async void InputField_KeyPressEditorAction(object sender, EventArgs e)
{
try
{
var ke = e as View.KeyEventArgs;
var eae = e as TextView.EditorActionEventArgs;
if (ke != null)
{
ke.Handled = false;
}
if (eae != null)
{
eae.Handled = false;
}
if (ke != null && (ke.Event.Action == KeyEventActions.Down ) &&
(ke.KeyCode == Keycode.Enter ) ||
eae != null && eae.ActionId == ImeAction.Done)
{
// some logic
//.
//.
//.
//.
//.
await ScanTu();
// more logic
//.
//.
//.
//.
//.
if (ke != null)
{
ke.Handled = true;
}
if (eae != null)
{
eae.Handled = true;
}
}
}
catch (Exception ex)
{
Log.Write(
this,
$"Method {new StackTrace(ex).GetFrame(0).GetMethod().Name} threw error: {ex}",
Log.DEBUG_LEVELS.ERROR);
}
}
当我在具有Android 4.3的物理设备M3SM10条形码扫描仪上运行代码时,无法重现该问题。没有连接时,ScanTu()
上会显示AlertDialog,用户必须单击确定重试该操作。也许这是事件再次触发的地方?