2

We have developed an application in Xamarin Forms. In Android application when the user uses the app in a low-network for about 90 seconds we are getting app not responding(ANR) Popup. Here my question is, is there any way to avoid this ANR popup in my application? In other words, is there any way to force the android system to wait for longer time?

In our Application when the user launching the application we are doing multiple tasks on threads which are majorly running on the secondary threads like:

  • Initialize Google Map & Creating Pins & Polyline Drawing

  • Firebase Listener Register

  • REST API calls

  • Loading List Items

So, before the device completes the above the list of task, if the users keep on touching the screen, then this causes multiple events to be queued in the main thread due to which we are getting ANR(App Not Responding Popup).

Here, we intend to disable the touch event until we complete the main thread in the existing task.

Changepond
  • 21
  • 1
  • 2
    You can not change the OS level triggers that cause an ANR to appear, but there things such as enabling `StrictMode` during development cycles (and pulling ANR traces) that can focus your intention on the areas that are coded incorrectly. I would recommend reading Google's ANR doc: https://developer.android.com/topic/performance/vitals/anr – SushiHangover May 26 '20 at 18:41

1 Answers1

1

You can use the below logic to restrict touches to the content of the page below the activity indicator to resolve your issue.

However, the touches for the Grid below will still be listened to by the Android system and it will be processed. Here you can only restrict the interaction to your application views. However, the touch listened by the Android system for the Grid, ContentView, or ActivityIndicator in the below code can never be ignored.

Ideally, no user will try to touch more number of times after realizing there is no interaction when the loader is loading. So I guess you can safely ignore this case considering the general user thought process.

<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;
    }
}
Community
  • 1
  • 1
Harikrishnan
  • 1,474
  • 2
  • 11
  • 25