首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

处理窗口还原状态有关问题

2012-09-29 
处理窗口还原状态问题处理窗口还原状态问题(一般用于横竖屏切换),除了在Activity中可以调用外,开发游戏时

处理窗口还原状态问题

处理窗口还原状态问题(一般用于横竖屏切换),除了在Activity中可以调用外,开发游戏时我们尽量在View中使用类似

@Override ?

??protected Parcelable onSaveInstanceState() { ?

?? ? ?Parcelable p = super.onSaveInstanceState(); ?

?? ? ?Bundle bundle = new Bundle(); ?

?? ? ?bundle.putInt("x", pX); ?

?? ? ?bundle.putInt("y", pY); ?

?? ? ?bundle.putParcelable("android123_state", p); ?

?? ? ?return bundle; ?

??} ?

??@Override ?

??protected void onRestoreInstanceState(Parcelable state) { ??

?? ? ?Bundle bundle = (Bundle) state; ?

?? ? ?dosomething(bundle.getInt("x"), bundle.getInt("y")); //获取刚才存储的x和y信息 ?

?? ? ?super.onRestoreInstanceState(bundle.getParcelable("android123_state")); ?

?? ? ?return; ?

??} ?

热点排行