Skip to content

Instantly share code, notes, and snippets.

@agustarc
Created December 22, 2016 13:00
Show Gist options
  • Save agustarc/3c39e6407e57d0a1ac109b1189ae80ae to your computer and use it in GitHub Desktop.
Save agustarc/3c39e6407e57d0a1ac109b1189ae80ae to your computer and use it in GitHub Desktop.
public class NonLeakActivity extends Activity {
private NonLeakHandler handler = new NonLeakHandler(this);
private static final class NonLeakHandler extends Handler {
private final WeakReference<NonLeakActivity> ref;
public NonLeakHandler(NonLeakActivity act) {
ref = new WeakReference<>(act);
}
@Override
public void handleMessage(Message msg) {
NonLeakActivity act = ref.get();
if (act != null) {
// do work
}
}
}
private static final Runnable runnable = new Runnable() {
@Override
public void run() {}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
handler.postDelayed(runnable, 60000);
finish();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment