0

My application constantly does API requests and I am checking connection status with ConnectivityManager. If it's connected then requesting for a data from the server, if not showing an error dialog that says Not connected to internet.

Well above method is manageable, but I wanted to have much more cleaner method for checking connectivity status and was thinking of Annotation Processing Library. Something like if I put @RequiresConnection annotation on my method that requests connection, then if it's not connected then it will automatically fire an error dialog with a retry button invoking the function that didn't get executed. So whenever user pressed a Retry button of dialog, it again tries to execute that function?

I am thinking of doing this annotation processing myself, but if it's already out there with I wanted to use it. Is there any such library?

Subhanshuja
  • 390
  • 1
  • 3
  • 20
musooff
  • 6,412
  • 3
  • 36
  • 65

1 Answers1

0

With Retrofit 2, you can use an OkHttp Interceptor implementation to check for network connectivity ahead of sending the request. If no network, throw an exception or Toast an error.

Amirhosein
  • 4,266
  • 4
  • 22
  • 35