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.

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.