Skip to content

Instantly share code, notes, and snippets.

@tophyr
Created July 7, 2014 21:52
Show Gist options
  • Save tophyr/4166db8e23bdf8c97a9a to your computer and use it in GitHub Desktop.
Save tophyr/4166db8e23bdf8c97a9a to your computer and use it in GitHub Desktop.
public class Foo {
private Handler mHandler;
private Runnable mJob;
private BroadcastReceiver mBR1 = new BroadcastReceiver() {
public Object mUnreachable;
@Override
public void onReceive(Intent i) {
Object goesAway = new Object();
Foo.this.mJob = new Runnable() { ... };
Foo.this.mHandler.postDelayed(mJob, 1000); // run mJob in 1 second
}
}
private BroadcastReceiver mBR2 = new BroadcastReceiver() {
@Override
public void onReceive(Intent i) {
Foo.this.mHandler.remove(Foo.this.mJob);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment