gpt4 book ai didi

java - 上下文和 Activity 有什么区别?

转载 作者:太空宇宙 更新时间:2023-11-03 11:30:16 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Difference between Activity Context and Application Context

何时使用上下文和 Activity 。我已经阅读了在 Constructor 中使用 Context 和 Activity 作为参数的代码,如下所示,请澄清一下

public AmazedView(Context context, Activity activity) {
super(context);

mActivity = activity;

// init paint and make is look "nice" with anti-aliasing.
mPaint = new Paint();
mPaint.setTextSize(14);
mPaint.setTypeface(mFont);
mPaint.setAntiAlias(true);

// setup accelerometer sensor manager.
mSensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE);
// register our accelerometer so we can receive values.
// SENSOR_DELAY_GAME is the recommended rate for games
mSensorManager.registerListener(mSensorAccelerometer, SensorManager.SENSOR_ACCELEROMETER,
SensorManager.SENSOR_DELAY_GAME);

// setup our maze and marble.
mMaze = new Maze(mActivity);
mMarble = new Marble(this);

// load array from /res/values/strings.xml
mStrings = getResources().getStringArray(R.array.gameStrings);

// set the starting state of the game.
switchGameState(GAME_INIT);
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com