4 使 用 静态 handler 夸类传递消息
主类中:
public static Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
// 获得数据
Bundle bundle = msg.getData();
during = bundle.getInt("during");
currentPosition = bundle.getInt("currentPosition");
}
};
其他类中:
int currentPosition = mediaPlayer.getCurrentPosition();//当前播放位置
// 问题? 当前的两个值 怎样传到主activity ---- 使用handler
Message msg= Message.obtain();
// 使用msg发送多条数据
Bundle bundle = new Bundle();// bundle 封装了map
bundle.putInt("during",during);
bundle.putInt("currentPosition",currentPosition);
msg.setData(bundle);
MainActivity.handler.sendMessage(msg);
}
网友评论