事件在Android Emulator和某些物理设备上不断触发

时间:2019-01-10 09:48:40

标签: android xamarin.android async-await eventhandler

我有运行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,用户必须单击确定重试该操作。也许这是事件再次触发的地方?

0 个答案:

没有答案