Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Last active December 6, 2019 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssaurel/9bf7a346b5a679a6309c3adc4eca2981 to your computer and use it in GitHub Desktop.
Save ssaurel/9bf7a346b5a679a6309c3adc4eca2981 to your computer and use it in GitHub Desktop.
Bitcoin Price Watcher on the SSaurel's Blog
private void launchTimer() {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
loadBitcoinPrice(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
String str = response.body().string();
parseBitcoinPrice(str);
}
@Override
public void onFailure(Call call, IOException ioe) { }
});
}
}, 0, PERIOD);
}
private void cancelTimer() {
if (timer != null) {
timer.cancel();
}
}
private void loadBitcoinPrice(Callback callback) {
Request request = new Request.Builder().url(BITCOIN_PRICE_ENDPOINT).build();
client.newCall(request).enqueue(callback);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment