Last year i create a method through which i can make multiple web call with single Async class. I am keep trying to update and some feature in that. At this time i make some changes in it and add some more functionality which save your time.

 

  1. Now no need to add extra check for internet connection.
  2. You can turn on/off dialog box.
  3. Set custom text over dialog box easily.
  4. Make GET/POST request from same class.
  5. No external lib required.

I upload my complete code to git if you like to add some thing in it which help people go ahead.

Git Link: https://github.com/anehkumar/AsyncReuse.

If you never tried this class before i will explain you in simple step how you can use this in your project.

Step 1. Create new project in your Android studio.

Step 2. Download my sample code from git.

Step 3. After download my code go to AsyncReuse/app/src/main/java/com/sampleasyncreuse/ in your downloaded code and copy AsyncReuse.java and GetResponse.java in your project. These two class are main through which you can make call to your web services and get response from that.

Step 4. Open that class where you want to send data to server and implement GetResponse interface and implement its method. As shown below code.

After implementation of interface you need to create instance of AsyncReuse class. I create a separate method in which i create object of my AsyncReuse class and pass required parameter in it.

You can pass your parameter using AsyncReuse Object and also set other option as shown below

After setting all this when you execute this, you get your response inside

getData() method. Hope this will help you. Please let me know if you implement some new and better thing in above code 🙂