Skip to content

Instantly share code, notes, and snippets.

@luizmarcus
Created February 22, 2016 23:35
Show Gist options
  • Save luizmarcus/e6bebbb144a440d1dee4 to your computer and use it in GitHub Desktop.
Save luizmarcus/e6bebbb144a440d1dee4 to your computer and use it in GitHub Desktop.
private static final String API_URL = "http://seusite.com/api";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView);
BackgroundTask task = new BackgroundTask();
task.execute();
}
private class BackgroundTask extends AsyncTask<Void, Void,
Pessoa> {
RestAdapter restAdapter;
@Override
protected void onPreExecute() {
restAdapter = new RestAdapter.Builder()
.setEndpoint(API_URL)
.build();
}
@Override
protected Pessoa doInBackground(Void... params) {
PessoaApi api = restAdapter.create(PessoaApi.class);
Pessoa pessoa = api.getPessoa("11111111111");
return pessoa;
}
@Override
protected void onPostExecute(Pessoa pessoa) {
textView.setText(pessoa.getNome());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment