Skip to content

Instantly share code, notes, and snippets.

@nottyo
Last active June 2, 2017 03:04
Show Gist options
  • Save nottyo/83fad435237d5d375b16868de4cf2138 to your computer and use it in GitHub Desktop.
Save nottyo/83fad435237d5d375b16868de4cf2138 to your computer and use it in GitHub Desktop.
LoadingActivity.java
private AsyncHttpClient asyncHttpClient;
public class LoadingActivity extends Activity {
private CountingIdlingResource idlingResource = EspressoIdlingResource.getCountingIdlingResource();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activiy_loading_screen);
asyncHttpClient = new AsyncHttpClient();
// increment the counter before calling any API.
idlingResource.increment();
asyncHttpClient.get(LoadingActivity.this, url, configurationCallback);
}
private JsonHttpResponseHandler configurationCallback = = new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject jsonObject) {
// decrement the counter when callback is invoked.
idlingResource.decrement();
Intent intent = new Intent(LoadingActivity.this, MainActivity.class);
startActivity(intent);
}
}
}
@VisibleForTesting
public IdlingResource getCountingIdlingResource(){
return EspressoIdlingResource.getCountingIdlingResource();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment