public abstract class WeakHandler<T>
extends android.os.Handler
#handleMessage(Message, T)
on subclasses when the reference to the object
is not lost yet.
Basically this enables us to create static handler classes while still be able to call through to the activity or context and store a reference to the handler as a normal class member.
Example for activity MyActivity
:
private static class MyHandler extends WeakHandler<MyActivity> { public MyHandler(MyActivity t) { super(t); } @Override public handleMessage(Message msg, MyActivity t) { // handle message normally here... } }Based on code taken from here http://pastebin.com/vCLY57Ug#
Constructor and Description |
---|
WeakHandler(T t)
Construct a Handler that has a weak reference to the object t of type T
|
Modifier and Type | Method and Description |
---|---|
void |
handleMessage(android.os.Message msg)
If the reference is valid, it invokes
#handleMessage(Message, T) . |
abstract void |
handleMessage(android.os.Message msg,
T t)
Must be implemented by subclasses in order to handle messages.
|
dispatchMessage, dump, getLooper, getMessageName, hasMessages, hasMessages, obtainMessage, obtainMessage, obtainMessage, obtainMessage, obtainMessage, post, postAtFrontOfQueue, postAtTime, postAtTime, postDelayed, removeCallbacks, removeCallbacks, removeCallbacksAndMessages, removeMessages, removeMessages, sendEmptyMessage, sendEmptyMessageAtTime, sendEmptyMessageDelayed, sendMessage, sendMessageAtFrontOfQueue, sendMessageAtTime, sendMessageDelayed, toString
public WeakHandler(T t)
t
- the object which this Handler will retain a reference topublic final void handleMessage(android.os.Message msg)
#handleMessage(Message, T)
.handleMessage
in class android.os.Handler
public abstract void handleMessage(android.os.Message msg, T t)
msg
- The message.t
- A strong reference to the object (usually an activity) which is guaranteed not to be null
.Handler.handleMessage(Message)