Back to project page Android-MyStarterApp.
The source code is released under:
Apache License
If you think the Android project Android-MyStarterApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package co.kaush.mystarterapp.app.network; // www .j a v a 2s . c o m import android.os.Handler; import java.lang.ref.WeakReference; public class BaseHandler { /** * Use this handler to prevent leaks */ public abstract static class StaticHandler<T> { private final static Handler mHandler = new Handler(); public static Runnable mStaticRunnable; private final WeakReference<T> mReference; public StaticHandler(WeakReference<T> objectForFutureReference) { super(); mReference = objectForFutureReference; mStaticRunnable = new Runnable() { @Override public void run() { codeToRun(); } }; } protected abstract void codeToRun(); public void postDelayed(long delayInMillis) { mHandler.postDelayed(mStaticRunnable, delayInMillis); } public T getWeaklyStoredObject() { return mReference.get(); } } }