How To Handle Deprecated Handler In Android
Previously this code worked perfect. Now its is showing android.os.handler is deprecated. private final Handler mHandler = new Handler() { @Override public void handleMessa
Solution 1:
As mentioned by Mike in the comments, Handler
is not deprecated. The way of creating an object of Handler using new Handler()
is deprecated.
As per the documentation, using new Handler()
can lead to bugs. So you should specify a looper for the handler explicitly. Looper must not be null.
Refer the code:
privatefinalHandlermHandler=newHandler(Looper.getMainLooper()) {
@OverridepublicvoidhandleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_STATE_CHANGE:
break;
}
}
Post a Comment for "How To Handle Deprecated Handler In Android"