Skip to content

Instantly share code, notes, and snippets.

@catalinghita8
Last active July 16, 2018 18:14
Show Gist options
  • Save catalinghita8/0ac5ecaf2024c03f14195f707cd6ff00 to your computer and use it in GitHub Desktop.
Save catalinghita8/0ac5ecaf2024c03f14195f707cd6ff00 to your computer and use it in GitHub Desktop.
public void loadData() {
// The network request might be handled in a different thread so make sure Espresso knows
// that the app is busy until the response is handled.
EspressoIdlingResource.increment(); // App is busy until further notice
// let's get the data
mRepository.getData(new LoadDataCallback() {
@Override
public void onDataLoaded(Data data) {
// now that the data has been loaded, we can mark the app as idle
// first, make sure the app is still marked as busy then decrement, there might be cases
// when other components finished their asynchronous tasks and marked the app as idle
if (!EspressoIdlingResource.getIdlingResource().isIdleNow()) {
EspressoIdlingResource.decrement(); // Set app as idle.
}
processData(data);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment