http communication using Retrofit2

Asked 2 years ago, Updated 2 years ago, 111 views

I tried using Retrofit2 library to get data through http communication.

I used the example on the official website.

The code seems simpler than when you didn't use the library

Getting the data from the example and spraying it to the activity takes a long time. About 3 seconds?

Is my method of using wrong?

If you have a good library, please recommend one~

public interface GitHubService {

    @GET("users/{user}/repos")
    Call<List<Repo>> listRepos(@Path("user") String user);

}
Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://api.github.com/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        GitHubService service = retrofit.create(GitHubService.class);
        final Call<List<Repo>> repos = service.listRepos("octocat");

        repos.enqueue(new Callback<List<Repo>>() {
            @Override
            public void onResponse(Call<List<Repo>> call, Response<List<Repo>> response) {
                List<Repo> repoList = response.body();
                textView.setText(repoList.toString());
            }

            @Override
            public void onFailure(Call<List<Repo>> call, Throwable t) {

            }
        });

android retrofit http

2022-09-22 21:59

1 Answers

I've been using it too, and that happens...

"We use Dynamic Proxy internally and parse the annotation at runtime. From the second call, the information in the annotation is cached, but the first call may be prolonged"

http://d2.naver.com/helloworld/377316


2022-09-22 21:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.