Created
February 22, 2016 23:35
-
-
Save luizmarcus/e6bebbb144a440d1dee4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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