Previously this code worked perfect.
Now its is showing android.os.handler is deprecated.
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_STATE_CHANGE:
break;
}
}
How can we resolve this issue.
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:
private final Handler mHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_STATE_CHANGE:
break;
}
}