import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class HandlerActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.handler);
super.onCreate(savedInstanceState);
}
/**切换屏幕之前将数据保存在Bundle中**/
@Override
protected void onSaveInstanceState(Bundle outState) {
long outTime = System.currentTimeMillis();
//屏幕切换将当前的时候保存在Bundle中
outState.putLong("time", outTime);
Log.v("InstanceState", "outTime is "+ outTime);
super.onSaveInstanceState(outState);
}
/**切换屏幕之后在Bundle中把数据取出来**/
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
//取出屏幕切换前保存的时间
Long saveTime = savedInstanceState.getLong("time");
Log.v("InstanceState", "saveTime is "+ saveTime);
super.onRestoreInstanceState(savedInstanceState);
}
}
转自http://disanji.net/2011/08/30/android游戏开发之横竖屏的切换/
切换横竖屏幕是的数据保存与传递
最新推荐文章于 2021-05-27 05:44:49 发布