//在广播类里,当接收到广播之后
case TelephonyManager.CALL_STATE_OFFHOOK:
CallHandler handler=new CallHandler(MainActivity.callActivity); //MainActivity.callActivity是MainActivity初始化的实例对象
handler.sendEmptyMessage(1);
break;
public class CallHandler extends Handler {
//弱引用
WeakReference<MainActivity> mActivity;
CallHandler(MainActivity activity)
{
mActivity=new WeakReference<MainActivity>(activity);
}
@Override
public void handleMessage(Message msg) {
MainActivity theActivity = mActivity.get();
if (msg.what == 0) {
//更新UI操作
theActivity.timeUIUpdate();
}else if (msg.what == 1) {
//更改UI操作
theActivity.callUIUpdate();
}
}
}
//在广播类里,当接收到广播之后
case TelephonyManager.CALL_STATE_OFFHOOK:
CallHandler handler=new CallHandler(MainActivity.callActivity); //MainActivity.callActivity是MainActivity初始化的实例对象
handler.sendEmptyMessage(1);
break;