Retrofit 2.1 used for all activities

compile 'com.squareup.retrofit2:retrofit:2.1.0'

compile 'com.squareup.retrofit2:converter-gson:2.1.0'

public class RetroHelper {

private final String BASEURL = "http://drapp.------demos.in/index.php/";

private static Context mContext;

public static Retrofit getAdapter(Context ctx, String serverUrl) {

mContext = ctx;

Gson gson = new Gson();

Retrofit retrofit = new Retrofit.Builder()

.baseUrl(BASEURL + serverUrl)

.addConverterFactory(GsonConverterFactory.create(gson))

.build();

return retrofit;

}

}

public interface ServiceOperations {

@GET("doctorapp_services/getSpecializations")

Call<Example> all();

}

public class Util {

public ServiceOperations getBaseClassService(Context ctx,String url){

return new RetroHelper().getAdapter(ctx,url).create(ServiceOperations.class);

}

}

public class MainActivity extends AppCompatActivity {

Util mUtil;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mUtil = new Util();

Call<Example> call = mUtil.getBaseClassService(MainActivity.this,"").all();

call.enqueue(new Callback<Example>() {

@Override

public void onResponse(Call<Example> call, Response<Example> response) {

Log.d("Lokesh",""+response.message());

Toast.makeText(MainActivity.this, response.isSuccessful()+"", Toast.LENGTH_SHORT).show();

Example examples =response.body();

if(examples == null){

Toast.makeText(MainActivity.this, "it is null", Toast.LENGTH_SHORT).show();

}else {

Toast.makeText(MainActivity.this, examples.getData().get(0).getSpecializationName(), Toast.LENGTH_SHORT).show();

}

}

@Override

public void onFailure(Call<Example> call, Throwable t) {

}

});

}

}