【问题标题】:Xamarin Forms Android application throwing ANR Popup After 90 secondsXamarin Forms Android 应用程序在 90 秒后抛出 ANR 弹出窗口
【发布时间】:2020-05-26 18:32:05
【问题描述】:

我们在 Xamarin Forms 中开发了一个应用程序。在 Android 应用程序中,当用户在低网络中使用应用程序大约 90 秒时,我们会收到应用程序无响应(ANR)弹出窗口。我的问题是,有什么方法可以避免在我的应用程序中出现此 ANR 弹出窗口?也就是说,有没有办法让android系统等待更长的时间?

在我们的应用程序中,当用户启动应用程序时,我们在线程上执行多个任务,这些线程主要在辅助线程上运行,例如:

  • 初始化谷歌地图并创建图钉和折线图

  • Firebase 监听器注册

  • REST API 调用

  • 加载列表项

因此,在设备完成上述任务列表之前,如果用户继续触摸屏幕,则会导致多个事件在主线程中排队,因此我们得到 ANR(App Not Responding Popup) .

在这里,我们打算禁用触摸事件,直到我们完成现有任务中的主线程。

【问题讨论】:

  • 您不能更改导致 ANR 出现的操作系统级别触发器,但是在开发周期中启用 StrictMode(并拉取 ANR 跟踪)等可以将您的意图集中在以下区域上:编码不正确。我建议阅读 Google 的 ANR 文档:developer.android.com/topic/performance/vitals/anr

标签: xamarin xamarin.forms xamarin.android android-anr-dialog


【解决方案1】:

您可以使用以下逻辑限制对活动指示器下方页面内容的触摸以解决您的问题。

但是,Android 系统仍会监听下方 Grid 的触摸并对其进行处理。在这里,您只能将交互限制在您的应用程序视图中。但是下面代码中Android系统对Grid、ContentView或ActivityIndi​​cator监听的触摸是绝对不能忽略的。

理想情况下,没有用户会在加载程序加载时意识到没有交互后尝试触摸更多次。因此,考虑到一般用户的思考过程,我想您可以放心地忽略此案例。

<Grid Grid.RowSpan="2" 
        InputTransparent="{Binding IsPageInteractable}" 
        IsVisible="{Binding IsPageBusy}">
    <ContentView Opacity="0.2" 
                    BackgroundColor="#4B4B4B" 
                    VerticalOptions="FillAndExpand" 
                    HorizontalOptions="FillAndExpand" />
    <ActivityIndicator IsRunning="{Binding IsPageBusy}" 
                        HorizontalOptions="CenterAndExpand" 
                        VerticalOptions="CenterAndExpand" />
</Grid>
public bool IsPageInteractable
{
    get { return _isPageInteractable; }
    set { _isPageInteractable = value; }
}

public bool IsPageBusy
{
    get { return _isPageBusy; }
    set
    {
        _isPageBusy = value;
        this.IsPageInteractable = !value;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-18
    • 1970-01-01
    相关资源
    最近更新 更多