参考
http://blog.csdn.net/qiaoning13256/article/details/7783602
具体到SurfaceView类里面,可以参考
static class MsgHandler extends Handler {
private WeakReference<FightView> mSurfaceView;
MsgHandler(FightView surfaceView) {
mSurfaceView = new WeakReference<FightView>(surfaceView);
}
@Override
public void handleMessage(Message msg) {
FightView surfaceView = mSurfaceView.get();
if (surfaceView != null) {
switch(msg.what) {
case GameConstant.EXIT:
surfaceView.confirmExit();
break;
case GameConstant.GAMEOVER:
surfaceView.confirmGameOver();
break;
case GameConstant.GAMEFINAL:
surfaceView.confirmGameFinal();
break;
case GameConstant.SHOWACTIONCHANGE: //提示战斗信息
Toast.makeText(surfaceView.getContext(),"战斗信息",Toast.LENGTH_SHORT).show();
break;
}
}
}
}
private Handler h = new MsgHandler(this);