Search code examples
androidandroid-fragmentsnavigation-drawergeneral-network-error

Best approach to show network error in android in Android with Tap to Retry option


I have Navigation Drawer in my application with several Fragments and few new Activity also apart from main application flow.

  • Current Functionality
    For navigating to each Fragment, Network is required and in case of any network error, I used to show Dialog. User needs to click on "OK" button and again go back to navigation drawer to retry.
  • New Approach I am trying
    User should be shown and error screen similar to LinkedIn android app with option to retry. enter image description here

As inner Fragments and handling call back can be cumbersome, how to handle this situation efficiently?
For individual Activities this can be achieved easily, but worried about the Navigation Drawer and inner Fragments.
Any suggestions?


Solution

  • Make this error layout hidden in this fragment. When there is any network error then change its visibility to VISIBLE. and in this hidden layout add a button to recall same method to check network connection etc.

    Let say you have fragment xml like - fragment -
    Relative Layout consisting - 1. -All layouts (VISIBLE) & 2. -Hidden network error layout with a button (GONE)

    When there is network error then change 1. 's visibility to - GONE and 2.'s visibility to VISIBLE

    and on retry button call -

    checkNetworkConnectionCall(); 
    

    I hope this will solve you problem.